Skip to content

Commit

Permalink
Fix logic for skipping preamble header with loguru
Browse files Browse the repository at this point in the history
- The previous logic hacked the `g_stderr_verbosity` boolean
  to make loguru skip preamble header output during the `loguru::init`
  call.
- After the change from 12d82bb,
  the `g_stderr_verbosity` was left in an inconsistent `WARNING`
  value when `argc == 0`.
- This commit fixes the logic by using the `loguru::g_preamble`
  variable to turn off preamble output during init. The state of
  this boolean is restored to it's previous value after init.
  • Loading branch information
jspanchu committed Jan 6, 2025
1 parent 0bf46f5 commit eb57cea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Common/Core/vtkLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ void vtkLogger::Init(int& argc, char* argv[], const char* verbosity_flag /*= "-v
loguru::g_preamble_time = false;
loguru::g_internal_verbosity = static_cast<loguru::Verbosity>(vtkLogger::InternalVerbosityLevel);

if (loguru::g_internal_verbosity > loguru::g_stderr_verbosity)
bool currentPreambleValue = loguru::g_preamble;
if (loguru::g_preamble && (loguru::g_internal_verbosity > loguru::g_stderr_verbosity))
{
// this avoids printing the preamble-header on stderr except for cases
// where the stderr log is guaranteed to have some log text generated.
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
loguru::g_preamble = false;
}
loguru::Options options;
options.verbosity_flag = verbosity_flag;
Expand All @@ -157,6 +158,7 @@ void vtkLogger::Init(int& argc, char* argv[], const char* verbosity_flag /*= "-v
}
loguru::init(
argc, argv, options); // initializes many things, one of them being g_stderr_verbosity
loguru::g_preamble = currentPreambleValue;
#else
(void)argc;
(void)argv;
Expand Down

0 comments on commit eb57cea

Please sign in to comment.