12 enum class loglevel_t {
17 ZERO // log absolutely nothing
20 extern loglevel_t log_level[2];
21 void enable_console_log(bool do_enable) noexcept;
22 void init_log(service_set *sset);
23 void setup_main_log(int fd);
24 bool is_log_flushed() noexcept;
25 void discard_console_log_buffer() noexcept;
27 void log(loglevel_t lvl, const char *msg) noexcept;
28 void log_msg_begin(loglevel_t lvl, const char *msg) noexcept;
29 void log_msg_part(const char *msg) noexcept;
30 void log_msg_end(const char *msg) noexcept;
31 void log_service_started(const char *service_name) noexcept;
32 void log_service_failed(const char *service_name) noexcept;
33 void log_service_stopped(const char *service_name) noexcept;
35 // Convenience methods which perform type conversion of the argument.
36 // There is some duplication here that could possibly be avoided, but
37 // it doesn't seem like a big deal.
38 static inline void log(loglevel_t lvl, const std::string &str) noexcept
40 log(lvl, str.c_str());
43 static inline void log_msg_begin(loglevel_t lvl, const std::string &str) noexcept
45 log_msg_begin(lvl, str.c_str());
48 static inline void log_msg_begin(loglevel_t lvl, int a) noexcept
50 constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2;
52 snprintf(nbuf, bufsz, "%d", a);
53 log_msg_begin(lvl, nbuf);
56 static inline void log_msg_part(const std::string &str) noexcept
58 log_msg_part(str.c_str());
61 static inline void log_msg_part(int a) noexcept
63 constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2;
65 snprintf(nbuf, bufsz, "%d", a);
69 static inline void log_msg_end(const std::string &str) noexcept
71 log_msg_end(str.c_str());
74 static inline void log_msg_end(int a) noexcept
76 constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2;
78 snprintf(nbuf, bufsz, "%d", a);
82 static inline void log_service_started(const std::string &str) noexcept
84 log_service_started(str.c_str());
87 static inline void log_service_failed(const std::string &str) noexcept
89 log_service_failed(str.c_str());
92 static inline void log_service_stopped(const std::string &str) noexcept
94 log_service_stopped(str.c_str());
97 // It's not intended that methods in this namespace be called directly:
99 template <typename A> static inline void log_parts(A a) noexcept
104 template <typename A, typename ...B> static inline void log_parts(A a, B... b) noexcept
111 // Variadic 'log' method.
112 template <typename A, typename ...B> static inline void log(loglevel_t lvl, A a, B ...b) noexcept
114 log_msg_begin(lvl, a);
115 dinit_log::log_parts(b...);