1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef __CEPH_LOG_LOG_H
5 #define __CEPH_LOG_LOG_H
7 #include "common/Thread.h"
9 #include "EntryQueue.h"
18 class Log : private Thread
20 Log **m_indirect_this;
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;
29 pthread_t m_queue_mutex_holder;
30 pthread_t m_flush_mutex_holder;
32 EntryQueue m_new; ///< new entries
33 EntryQueue m_recent; ///< recent (less new) entries we've already written at low detail
35 std::string m_log_file;
40 int m_fd_last_error; ///< last error we say writing to fd (if any)
42 int m_syslog_log, m_syslog_crash;
43 int m_stderr_log, m_stderr_crash;
44 int m_graylog_log, m_graylog_crash;
46 shared_ptr<Graylog> m_graylog;
50 int m_max_new, m_max_recent;
54 void *entry() override;
56 void _flush(EntryQueue *q, EntryQueue *requeue, bool crash);
58 void _log_message(const char *s, bool crash);
61 explicit Log(SubsystemMap *s);
64 void set_flush_on_exit();
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);
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);
83 shared_ptr<Graylog> graylog() { return m_graylog; }
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);
92 /// true if the log lock is held by our thread
93 bool is_inside_log_lock();
95 /// induce a segv on the next log event