16 inline std::string NowTime();
34 std::ostringstream& Get(TLogLevel level = logINFO);
37 static TLogLevel& ReportingLevel();
38 static std::string ToString(TLogLevel level);
39 static TLogLevel FromString(
const std::string& level);
42 std::ostringstream os;
46 Log& operator=(
const Log&);
51 inline std::ostringstream& Log::Get(TLogLevel level) {
52 os <<
"- " << NowTime();
53 os <<
" " << ToString(level) <<
": ";
54 os << std::string(level > logDEBUG ? level - logDEBUG : 0,
'\t');
60 std::cerr << os.str();
63 inline TLogLevel& Log::ReportingLevel() {
64 static TLogLevel reportingLevel = logDEBUG4;
65 return reportingLevel;
68 inline std::string Log::ToString(TLogLevel level) {
69 static const char*
const buffer[] = {
"NONE",
"ERROR",
"WARNING",
70 "INFO",
"DEBUG",
"DEBUG1",
71 "DEBUG2",
"DEBUG3",
"DEBUG4"};
75 inline TLogLevel Log::FromString(
const std::string& level) {
76 if (level ==
"DEBUG4")
return logDEBUG4;
77 if (level ==
"DEBUG3")
return logDEBUG3;
78 if (level ==
"DEBUG2")
return logDEBUG2;
79 if (level ==
"DEBUG1")
return logDEBUG1;
80 if (level ==
"DEBUG")
return logDEBUG;
81 if (level ==
"INFO")
return logINFO;
82 if (level ==
"WARNING")
return logWARNING;
83 if (level ==
"ERROR")
return logERROR;
84 if (level ==
"NONE")
return logNONE;
85 Log().Get(logWARNING) <<
"Unknown logging level '" << level
86 <<
"'. Using INFO level as default.";
92 #define FILE_LOG(level) \
93 if (level > FILELog::ReportingLevel()) \
98 inline std::string NowTime() {
100 ss << std::setfill(
'0') << std::setw(2);
102 using namespace std::chrono;
103 auto now = system_clock::now().time_since_epoch();
105 ss << duration_cast<hours>(now).count() % 24 <<
":"
106 << duration_cast<minutes>(now).count() % 60 <<
":"
107 << duration_cast<seconds>(now).count() % 60 <<
"."
108 << duration_cast<milliseconds>(now).count() % 1000;