log: allow lowercase LOG_LEVEL values

This commit is contained in:
Danny Robson 2014-09-11 15:33:46 +10:00
parent 9bd80ab85c
commit 25f6cd635b

View File

@ -58,8 +58,8 @@ level_to_string (level_t l) {
} }
level_t static level_t
string_to_level (const string &name) { string_to_level (string name) {
static const map <string, level_t> NAME_LEVELS = { static const map <string, level_t> NAME_LEVELS = {
{ "EMERGENCY", EMERGENCY }, { "EMERGENCY", EMERGENCY },
{ "ALERT", ALERT }, { "ALERT", ALERT },
@ -73,6 +73,8 @@ string_to_level (const string &name) {
{ "DEBUG", DEBUG } { "DEBUG", DEBUG }
}; };
std::transform (name.cbegin (), name.cend (), name.begin (), ::toupper);
auto pos = NAME_LEVELS.find (name); auto pos = NAME_LEVELS.find (name);
if (pos == NAME_LEVELS.end ()) if (pos == NAME_LEVELS.end ())
throw std::range_error (name); throw std::range_error (name);