29#include <sys/syscall.h>
37const char*
Labels[] = {
"NONE",
"CRIT",
"ERROR",
"WARN",
"METRIC",
"NOTICE",
"INFO",
"DEBUG"};
45 bool init_done =
false;
66struct LogBufPoolWrapper {
67 static constexpr std::size_t InitialPoolSize = 8;
78class NullLogger
final :
public Logger {
80 size_t ,
bool )
noexcept override
86class StdLogger
final :
public Logger {
110 size_t hlen{
strftime(head,
sizeof(head),
"%Y/%m/%d %H:%M:%S", &
tm)};
129class SysLogger
final :
public Logger {
257 write_all_messages();
260void AsyncLogger::write_all_messages()
266 if (
t.msg !=
nullptr) {
272 fake_pushed_count_.fetch_sub(
fake_count, std::memory_order_relaxed);
277 write_all_messages();
278 std::this_thread::sleep_for(50
ms);
280 return (!tq_.empty() || !stop_);
291 char*
const msg_ptr = msg.release();
293 return tq_.push(Task{.ts = ts, .level = level, .tid = tid, .msg = ptr, .size =
size});
297 const auto cnt = fake_pushed_count_.load(std::memory_order_relaxed);
298 const auto d = ts - last_time_fake_pushed_.load(std::memory_order_relaxed);
311 last_time_fake_pushed_.store(ts, std::memory_order_relaxed);
312 fake_pushed_count_.fetch_add(1, std::memory_order_relaxed);
319 }
catch (
const std::bad_alloc&) {