Browse Source

Merge pull request #5442

428249c5 easylogging++: minimal stdout logging format (moneromooo-monero)
Riccardo Spagni 4 months ago
parent
commit
213fd5007d
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

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

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

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

Loading…
Cancel
Save