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