21 #include <momemta/impl/logger/formatter.h> 23 #include <momemta/impl/logger/os.h> 27 void full_formatter::format(details::log_msg& msg) {
28 auto tm_time = details::os::localtime(log_clock::to_time_t(msg.time));
30 auto duration = msg.time.time_since_epoch();
31 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
33 msg.formatted << msg.index <<
": [" <<
static_cast<unsigned int>(tm_time.tm_year + 1900) <<
'-' 35 << std::setw(2) <<
static_cast<unsigned int>(tm_time.tm_mon + 1) <<
'-' 36 << std::setw(2) <<
static_cast<unsigned int>(tm_time.tm_mday) <<
' ' 37 << std::setw(2) <<
static_cast<unsigned int>(tm_time.tm_hour) <<
':' 38 << std::setw(2) <<
static_cast<unsigned int>(tm_time.tm_min) <<
':' 39 << std::setw(2) <<
static_cast<unsigned int>(tm_time.tm_sec) <<
'.' 40 << std::setw(3) <<
static_cast<unsigned int>(millis) <<
"] ";
44 msg.formatted <<
"] ";
46 msg.formatted << msg.raw.str();
48 msg.formatted.write(details::os::eol, details::os::eol_size);
51 void full_formatter::format_level(details::log_msg& msg) {
52 msg.formatted << ::logging::level::to_str(msg.level);
55 void ansi_color_full_formatter::format_level(details::log_msg& msg) {
57 case logging::level::trace:
58 case logging::level::debug:
59 msg.formatted << grey;
61 case logging::level::info:
62 msg.formatted << blue;
64 case logging::level::warning:
65 msg.formatted << yellow << bold;
67 case logging::level::error:
68 msg.formatted << red << bold;
70 case logging::level::fatal:
71 msg.formatted << bold << on_red;
73 case logging::level::off:
74 msg.formatted << reset;
79 msg.formatted << ::logging::level::to_str(msg.level) << reset;