Reputation: 6239
I'd like to be able to log for debugging purpose from a package that could be either part of a web app or a command line application
Current I use
print('some text');
But I cannot control at runtime what is printed (DEBUG, INFO, ...) While I'm used to use java.util.logging.Logger in java, I could not find a way to use the Logger class in the logging package of dart, in either a web or command line application.
Logger logger = new Logger('test');
logger.info('some text');
The simple code above compiles fine but I cannot see any ouput in either the console of Dartium or the Output pane in the DartEditor.
Has anyone successfully used it (and see some text)?
Upvotes: 5
Views: 1682
Reputation: 11171
In my Dart Bat-belt, I keep a function like this:
void printLogRecord(LogRecord r) {
print("${r.loggerName} ${r.level} ${r.message}");
}
Then I'll add it to a Logger, typically the root logger:
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen(printLogRecord);
Upvotes: 9
Reputation: 31
With the lastes m4 release this is the API that worked for me:
Logger.root.level = Level.FINEST;
Logger.root.onRecord.listen((LogRecord r) {
window.console.log('${r.loggerName}(${r.level}): ${r.message}');
});
Upvotes: 1