logging
logging copied to clipboard
Shortcut for creating child loggers
class Logger {
// ...
Logger call(String childName) {
return Logger('$fullName.$childName');
}
}
With the above call
method in the Logger
class, creating child loggers could be more convenient.
Example
For a method foo
, and bar
in class MyClass
:
Current way
class MyClass {
void foo() {
final log = Logger('MyClass.foo');
log.info('..some log..');
}
void bar() {
final log = Logger('MyClass.bar');
log.info('..some log..');
}
}
Proposed way
class MyClass {
final log = Logger('MyClass');
void foo() {
final log = this.log('foo');
log.info('..some log..');
}
void bar() {
final log = this.log('bar');
log.info('..some log..');
}
}
Would be like in Python logger getChild method, it would be nice :)
Also it could be done like this without any additional modification
final child = Logger('${log.fullName}.childname');
I agree. That's how I'm creating child loggers right now.