From dd00f4167ad96f9674474234432be534d322f607 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 6 Apr 2016 13:50:44 +1000 Subject: [PATCH] log: break after printing the log message --- log.cpp | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/log.cpp b/log.cpp index a2d8dc3a..1ecf9364 100644 --- a/log.cpp +++ b/log.cpp @@ -195,34 +195,32 @@ level_width (void) 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; + if (level <= LOG_LEVEL) { + 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; - std::string time_string (time_len - 1, '\0'); - time_t unix_time = time (nullptr); + if (0 == strftime (&time_string[0], + time_len, + "%Y-%m-%d %H%Mh%S", + localtime (&unix_time))) { + warn ("failed to log time"); + return; + } - if (0 == strftime (&time_string[0], - time_len, - "%Y-%m-%d %H%Mh%S", - localtime (&unix_time))) { - warn ("failed to log time"); - return; + std::cerr << time_string << " [" + << level_colour (level) + << std::setw (level_width ()) + << std::left + << level + << std::setw (0) + << util::term::csi::graphics::RESET + << "] " << msg << std::endl; } - std::cerr << time_string << " [" - << level_colour (level) - << std::setw (level_width ()) - << std::left - << level - << std::setw (0) - << util::term::csi::graphics::RESET - << "] " << msg << std::endl; + if (needs_break (level)) + breakpoint (); }