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 {
109 size_t hlen{
strftime(head,
sizeof(head),
"%Y/%m/%d %H:%M:%S", &
tm)};
129class SysLogger
final :
public Logger {
256 write_all_messages();
259void AsyncLogger::write_all_messages()
265 if (
t.msg !=
nullptr) {
271 fake_pushed_count_.fetch_sub(
fake_count, std::memory_order_relaxed);
276 write_all_messages();
277 std::this_thread::sleep_for(50
ms);
279 return (!tq_.empty() || !stop_);
290 char*
const msg_ptr = msg.release();
292 return tq_.push(Task{.ts = ts, .level = level, .tid = tid, .msg = ptr, .size =
size});
296 const auto cnt = fake_pushed_count_.load(std::memory_order_relaxed);
297 const auto d = ts - last_time_fake_pushed_.load(std::memory_order_relaxed);
310 last_time_fake_pushed_.store(ts, std::memory_order_relaxed);
311 fake_pushed_count_.fetch_add(1, std::memory_order_relaxed);
318 }
catch (
const std::bad_alloc&) {