Browse Source

easylogging++: minimal stdout logging format

It's a bit of a hack, but doing it right would need a lot
of changes to the easylogging++ source.
moneromooo-monero 2 months ago
parent
commit
428249c5d1
No account linked to committer's email address
2 changed files with 22 additions and 5 deletions
  1. 21
    4
      external/easylogging++/easylogging++.cc
  2. 1
    1
      external/easylogging++/easylogging++.h

+ 21
- 4
external/easylogging++/easylogging++.cc View File

@@ -2337,6 +2337,19 @@ base::threading::Mutex& LogDispatchCallback::fileHandle(const LogDispatchData* d
2337 2337
 namespace base {
2338 2338
 // DefaultLogDispatchCallback
2339 2339
 
2340
+const char* convertToChar(Level level) {
2341
+  // Do not use switch over strongly typed enums because Intel C++ compilers dont support them yet.
2342
+  if (level == Level::Global) return "G";
2343
+  if (level == Level::Debug) return "D";
2344
+  if (level == Level::Info) return "I";
2345
+  if (level == Level::Warning) return "W";
2346
+  if (level == Level::Error) return "E";
2347
+  if (level == Level::Fatal) return "F";
2348
+  if (level == Level::Verbose) return "V";
2349
+  if (level == Level::Trace) return "T";
2350
+  return "?";
2351
+}
2352
+
2340 2353
 void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
2341 2354
 #if defined(ELPP_THREAD_SAFE)
2342 2355
 #if 0
@@ -2345,11 +2358,15 @@ void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
2345 2358
 #endif
2346 2359
 #endif
2347 2360
   m_data = data;
2348
-  dispatch(m_data->logMessage()->logger()->logBuilder()->build(m_data->logMessage(),
2361
+  base::TypedConfigurations* tc = m_data->logMessage()->logger()->typedConfigurations();
2362
+  const base::LogFormat* logFormat = &tc->logFormat(m_data->logMessage()->level());
2363
+  dispatch(base::utils::DateTime::getDateTime(logFormat->dateTimeFormat().c_str(), &tc->subsecondPrecision(m_data->logMessage()->level()))
2364
+      + "\t" + convertToChar(m_data->logMessage()->level()) + " " + m_data->logMessage()->message() + "\n",
2365
+      m_data->logMessage()->logger()->logBuilder()->build(m_data->logMessage(),
2349 2366
            m_data->dispatchAction() == base::DispatchAction::NormalLog || m_data->dispatchAction() == base::DispatchAction::FileOnlyLog));
2350 2367
 }
2351 2368
 
2352
-void DefaultLogDispatchCallback::dispatch(base::type::string_t&& logLine) {
2369
+void DefaultLogDispatchCallback::dispatch(base::type::string_t&& rawLine, base::type::string_t&& logLine) {
2353 2370
   if (m_data->dispatchAction() == base::DispatchAction::NormalLog || m_data->dispatchAction() == base::DispatchAction::FileOnlyLog) {
2354 2371
     if (m_data->logMessage()->logger()->m_typedConfigurations->toFile(m_data->logMessage()->level())) {
2355 2372
       base::type::fstream_t* fs = m_data->logMessage()->logger()->m_typedConfigurations->fileStream(
@@ -2376,8 +2393,8 @@ void DefaultLogDispatchCallback::dispatch(base::type::string_t&& logLine) {
2376 2393
     if (m_data->dispatchAction() != base::DispatchAction::FileOnlyLog) {
2377 2394
       if (m_data->logMessage()->logger()->m_typedConfigurations->toStandardOutput(m_data->logMessage()->level())) {
2378 2395
         if (ELPP->hasFlag(LoggingFlag::ColoredTerminalOutput))
2379
-          m_data->logMessage()->logger()->logBuilder()->convertToColoredOutput(&logLine, m_data->logMessage()->level());
2380
-        ELPP_COUT << ELPP_COUT_LINE(logLine);
2396
+          m_data->logMessage()->logger()->logBuilder()->convertToColoredOutput(&rawLine, m_data->logMessage()->level());
2397
+        ELPP_COUT << ELPP_COUT_LINE(rawLine);
2381 2398
       }
2382 2399
     }
2383 2400
   }

+ 1
- 1
external/easylogging++/easylogging++.h View File

@@ -2776,7 +2776,7 @@ class DefaultLogDispatchCallback : public LogDispatchCallback {
2776 2776
   void handle(const LogDispatchData* data);
2777 2777
  private:
2778 2778
   const LogDispatchData* m_data;
2779
-  void dispatch(base::type::string_t&& logLine);
2779
+  void dispatch(base::type::string_t&& rawLine, base::type::string_t&& logLine);
2780 2780
 };
2781 2781
 #if ELPP_ASYNC_LOGGING
2782 2782
 class AsyncLogDispatchCallback : public LogDispatchCallback {

Loading…
Cancel
Save