-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
This is the cause of a pretty weird bug:
final filter = ProductionFilter();
final logger = Logger(filter: filter);
void main() {
filter.level = Level.warning;
logger.i("This is an info message and should not show"); // it shows
}
Took me a while to isolate the problem, but it is because logger
is lazily evaluated:
class MyFilter extends LogFilter {
Level _level = Level.info;
@override Level get level => _level;
@override set level(Level? value) {
print("Setting log level to $value");
_level = value ?? Level.info;
}
@override
bool shouldLog(LogEvent event) => event.level.index >= level.index;
}
final filter = MyFilter();
final logger = Logger(filter: filter, printer: SimplePrinter())..toString();
void main() {
filter.level = Level.warning;
logger.i("This is an info message and should not show"); // it shows
}
// Output:
// Setting level to warning
// Setting level to verbose
// [I] This is an info message and should not show
Turns out, when logger
is accessed for the first time, its constructor sets filter.level = Logger.level
, overriding any previous assignment. This should be removed so we can configure the log level of a global logger
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed