log: break after printing the log message

This commit is contained in:
Danny Robson 2016-04-06 13:50:44 +10:00
parent e321b9eee7
commit dd00f4167a

44
log.cpp
View File

@ -195,34 +195,32 @@ level_width (void)
void void
util::log (util::level_t level, const std::string &msg) 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 (); static const util::level_t LOG_LEVEL = log_level ();
if (level > LOG_LEVEL) if (level <= LOG_LEVEL) {
return; static const size_t time_len = strlen("YYYY-mm-dd HHMMhSS") + 1;
std::string time_string (time_len - 1, '\0');
time_t unix_time = time (nullptr);
static const size_t time_len = strlen("YYYY-mm-dd HHMMhSS") + 1; if (0 == strftime (&time_string[0],
std::string time_string (time_len - 1, '\0'); time_len,
time_t unix_time = time (nullptr); "%Y-%m-%d %H%Mh%S",
localtime (&unix_time))) {
warn ("failed to log time");
return;
}
if (0 == strftime (&time_string[0], std::cerr << time_string << " ["
time_len, << level_colour (level)
"%Y-%m-%d %H%Mh%S", << std::setw (level_width ())
localtime (&unix_time))) { << std::left
warn ("failed to log time"); << level
return; << std::setw (0)
<< util::term::csi::graphics::RESET
<< "] " << msg << std::endl;
} }
std::cerr << time_string << " [" if (needs_break (level))
<< level_colour (level) breakpoint ();
<< std::setw (level_width ())
<< std::left
<< level
<< std::setw (0)
<< util::term::csi::graphics::RESET
<< "] " << msg << std::endl;
} }