MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / Init

Method Init

src/util/log.cpp:72–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70Log::Log(LogLevel level_) : level(level_), buffer{}, stream{buffer} { Init(); }
71
72void Log::Init()
73{
74 std::lock_guard<std::mutex> lock(get_mutex());
75 if (!LogPolicy::GetInstance().IsMute() && level <= LogPolicy::GetInstance().GetLevel())
76 {
77 const bool is_terminal = IsStdoutATTY();
78
79 auto format = [is_terminal](const char *level, const char *color)
80 {
81 const auto now = std::chrono::system_clock::now();
82 const auto timestamp =
83 std::format("{:%FT%T}", std::chrono::floor<std::chrono::seconds>(now));
84 return std::format("{}[{}] [{}] ", is_terminal ? color : "", timestamp, level);
85 };
86
87 switch (level)
88 {
89 case logNONE:
90 break;
91 case logWARNING:
92 stream << format("warn", YELLOW);
93 break;
94 case logERROR:
95 stream << format("error", RED);
96 break;
97 case logDEBUG:
98#ifdef ENABLE_DEBUG_LOGGING
99 stream << format("debug", MAGENTA);
100#endif
101 break;
102 default: // logINFO:
103 stream << format("info", "");
104 break;
105 }
106 }
107}
108
109std::mutex &Log::get_mutex()
110{

Callers

nothing calls this directly

Calls 4

IsStdoutATTYFunction · 0.85
formatFunction · 0.85
IsMuteMethod · 0.80
GetLevelMethod · 0.80

Tested by

no test coverage detected