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.
This commit is contained in:
Danny Robson 2012-04-26 18:22:24 +10:00
parent 2515db00f2
commit d8b74be608

18
log.cpp
View File

@ -93,8 +93,26 @@ util::log (level_t l, const std::string &format)
{ detail::log (l, boost::format (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 void
util::detail::log (level_t level, boost::format &&format) { 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] "); static const boost::format LEVEL_FORMAT ("%s [%s] ");
char time_string[strlen("YYYY-mm-dd HHMMh") + 1]; char time_string[strlen("YYYY-mm-dd HHMMh") + 1];