我希望能够从可以作为Web应用程序或命令行应用程序的一部分的程序包中进行调试
我目前使用的
print('some text');
Run Code Online (Sandbox Code Playgroud)
但我无法在运行时控制打印的内容(DEBUG,INFO,...)虽然我习惯在java中使用java.util.logging.Logger,但我找不到在日志包中使用Logger类的方法在web或命令行应用程序中的dart.
Logger logger = new Logger('test');
logger.info('some text');
Run Code Online (Sandbox Code Playgroud)
上面的简单代码编译得很好,但我无法在Dartium的控制台或DartEditor的Output窗格中看到任何输出.
有没有人成功使用它(并看到一些文字)?
在我的Dart Bat-belt中,我保留了这样的功能:
void printLogRecord(LogRecord r) {
print("${r.loggerName} ${r.level} ${r.message}");
}
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到Logger,通常是根记录器:
Logger.root.level = Level.FINE;
Logger.root.onRecord.listen(printLogRecord);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1272 次 |
| 最近记录: |