]> git.proxmox.com Git - ceph.git/blob - ceph/src/log/Log.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / log / Log.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef __CEPH_LOG_LOG_H
5 #define __CEPH_LOG_LOG_H
6
7 #include "common/Thread.h"
8
9 #include "EntryQueue.h"
10
11 namespace ceph {
12 namespace logging {
13
14 class Graylog;
15 class SubsystemMap;
16 class Entry;
17
18 class Log : private Thread
19 {
20 Log **m_indirect_this;
21
22 SubsystemMap *m_subs;
23
24 pthread_mutex_t m_queue_mutex;
25 pthread_mutex_t m_flush_mutex;
26 pthread_cond_t m_cond_loggers;
27 pthread_cond_t m_cond_flusher;
28
29 pthread_t m_queue_mutex_holder;
30 pthread_t m_flush_mutex_holder;
31
32 EntryQueue m_new; ///< new entries
33 EntryQueue m_recent; ///< recent (less new) entries we've already written at low detail
34
35 std::string m_log_file;
36 int m_fd;
37 uid_t m_uid;
38 gid_t m_gid;
39
40 int m_fd_last_error; ///< last error we say writing to fd (if any)
41
42 int m_syslog_log, m_syslog_crash;
43 int m_stderr_log, m_stderr_crash;
44 int m_graylog_log, m_graylog_crash;
45
46 shared_ptr<Graylog> m_graylog;
47
48 bool m_stop;
49
50 int m_max_new, m_max_recent;
51
52 bool m_inject_segv;
53
54 void *entry() override;
55
56 void _flush(EntryQueue *q, EntryQueue *requeue, bool crash);
57
58 void _log_message(const char *s, bool crash);
59
60 public:
61 explicit Log(SubsystemMap *s);
62 ~Log() override;
63
64 void set_flush_on_exit();
65
66 void set_max_new(int n);
67 void set_max_recent(int n);
68 void set_log_file(std::string fn);
69 void reopen_log_file();
70 void chown_log_file(uid_t uid, gid_t gid);
71
72 void flush();
73
74 void dump_recent();
75
76 void set_syslog_level(int log, int crash);
77 void set_stderr_level(int log, int crash);
78 void set_graylog_level(int log, int crash);
79
80 void start_graylog();
81 void stop_graylog();
82
83 shared_ptr<Graylog> graylog() { return m_graylog; }
84
85 Entry *create_entry(int level, int subsys);
86 Entry *create_entry(int level, int subsys, size_t* expected_size);
87 void submit_entry(Entry *e);
88
89 void start();
90 void stop();
91
92 /// true if the log lock is held by our thread
93 bool is_inside_log_lock();
94
95 /// induce a segv on the next log event
96 void inject_segv();
97 void reset_segv();
98 };
99
100 }
101 }
102
103 #endif