LoggerConfig constructor
LoggerConfig(
- ConfigMap map
Constructs a collection of logger levels.
Extracts logger names and levels from the config map
.
The named levels are the same as those defined by the logging package: ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, SHOUT and OFF.
The logger names and the levels are both case-sensitive.
Implementation
LoggerConfig(ConfigMap map) {
for (final k in map.keys()) {
assert(!levels.containsKey(k), 'duplicate should never happen');
// Get the value for the level
final type = map.type(k);
Level level;
if (type == ConfigType.string) {
// Named level
final name = map.string(k);
// Look in [Level.LEVELS] to find a level that matches the name
try {
level = Level.LEVELS.firstWhere((x) => x.name == name);
// ignore: avoid_catching_errors
} on StateError {
throw ConfigExceptionValue(
'level unknown ("$name")', map.path, k, name);
}
} else if (type == ConfigType.integer) {
// Numeric level
final num = map.integer(k);
// Note: ALL is smaller than FINEST and OFF is larger than SHOUT, so
// it is possible for custom levels to be more finer than the finest and
// greater than shouting.
if (num < Level.ALL.value && Level.OFF.value < num) {
throw ConfigExceptionValue(
'level out of range [${Level.ALL.value}-${Level.OFF.value}]',
map.path,
k,
num);
// could have passed max and min to `integer`, but doing it this
// way allows a customised error message to be produced.
}
level = Level('CUSTOM_$num', num);
} else {
// Neither a string nor an integer
throw ConfigExceptionKey('level not a string or integer', map.path, k);
}
// Store the level
levels[k] = level;
}
}