From d8b74be608737d09e71ca55ba0b62f949585343c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 26 Apr 2012 18:22:24 +1000 Subject: [PATCH] Read a maximum output level from the env. Importantly this does not change whether log parameters are evaluated, it simply prevents output to the log stream; ie, it is purely aethetic. --- log.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/log.cpp b/log.cpp index 6a6b77b0..73a8d5c5 100644 --- a/log.cpp +++ b/log.cpp @@ -93,8 +93,26 @@ util::log (level_t l, const std::string &format) { detail::log (l, boost::format (format)); } +static level_t +log_level (void) { + const char *env = getenv ("LOG_LEVEL"); + if (!env) + return DEFAULT; + + try { + return string_to_level (env); + } catch (...) { + return DEFAULT; + } +} + + void util::detail::log (level_t level, boost::format &&format) { + static const level_t LOG_LEVEL = log_level (); + if (level > LOG_LEVEL) + return; + static const boost::format LEVEL_FORMAT ("%s [%s] "); char time_string[strlen("YYYY-mm-dd HHMMh") + 1];