]> git.proxmox.com Git - ceph.git/blob - ceph/src/log/Log.h
update sources to v12.2.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 std::string m_log_stderr_prefix;
47
48 shared_ptr<Graylog> m_graylog;
49
50 bool m_stop;
51
52 int m_max_new, m_max_recent;
53
54 bool m_inject_segv;
55
56 void *entry() override;
57
58 void _flush(EntryQueue *q, EntryQueue *requeue, bool crash);
59
60 void _log_message(const char *s, bool crash);
61
62 public:
63 explicit Log(SubsystemMap *s);
64 ~Log() override;
65
66 void set_flush_on_exit();
67
68 void set_max_new(int n);
69 void set_max_recent(int n);
70 void set_log_file(std::string fn);
71 void reopen_log_file();
72 void chown_log_file(uid_t uid, gid_t gid);
73 void set_log_stderr_prefix(const std::string& p);
74
75 void flush();
76
77 void dump_recent();
78
79 void set_syslog_level(int log, int crash);
80 void set_stderr_level(int log, int crash);
81 void set_graylog_level(int log, int crash);
82
83 void start_graylog();
84 void stop_graylog();
85
86 shared_ptr<Graylog> graylog() { return m_graylog; }
87
88 Entry *create_entry(int level, int subsys);
89 Entry *create_entry(int level, int subsys, size_t* expected_size);
90 void submit_entry(Entry *e);
91
92 void start();
93 void stop();
94
95 /// true if the log lock is held by our thread
96 bool is_inside_log_lock();
97
98 /// induce a segv on the next log event
99 void inject_segv();
100 void reset_segv();
101 };
102
103 }
104 }
105
106 #endif