14 #include <fmt/format.h> 22 m_file = fopen(path.c_str(),
"we");
25 throw std::runtime_error(fmt::format(
26 "Could not open log file: {}", strerror(errno)
40 memset(&tv, 0,
sizeof(tv));
41 gettimeofday(&tv,
nullptr);
44 memset(&btime, 0,
sizeof(tv));
45 localtime_r(&tv.tv_sec, &btime);
48 strftime(timeString,
sizeof(timeString),
"%a %F %T", &btime);
50 unsigned int len =
event.message.length();
51 while(len != 0 && (event.
message[len-1] ==
'\n' || event.
message[len-1] ==
'\r'))
54 fmt::print(
m_file,
"{}.{:03d}: {:>20}: ",
55 timeString, tv.tv_usec / 1000,
Logger(const std::string &path, bool flush=false)
Constructor.
void log(const LogEvent &event)
Log message.