log: add breakpoints when BREAK_LEVEL is reached
This commit is contained in:
parent
9f6d41eb8c
commit
800d7fef00
26
log.cpp
26
log.cpp
@ -95,10 +95,36 @@ log_level (void)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static bool
|
||||
needs_break (util::level_t level)
|
||||
{
|
||||
static util::level_t break_level;
|
||||
static bool has_level = [&] (void) {
|
||||
const char *env = getenv ("BREAK_LEVEL");
|
||||
if (!env)
|
||||
return false;
|
||||
|
||||
try {
|
||||
break_level = to_level (env);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
} ();
|
||||
|
||||
return has_level && level <= break_level;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
util::log (util::level_t level, const std::string &msg)
|
||||
{
|
||||
// fire a breakpoint before the following early exit
|
||||
if (needs_break (level))
|
||||
breakpoint ();
|
||||
|
||||
static const util::level_t LOG_LEVEL = log_level ();
|
||||
if (level > LOG_LEVEL)
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user