文档说
var logger = Logger(
filter: null, // Use the default LogFilter (-> only log in debug mode)
printer: PrettyPrinter(), // Use the PrettyPrinter to format and print log
output: null, // Use the default LogOutput (-> send everything to console)
);
Run Code Online (Sandbox Code Playgroud)
我对输出的参数应该是什么以使其记录到文件感到困惑
像file(../lib/file.txt)什么?
@用户2962142,
您必须使用扩展 LogOutput 创建类 FileOutput 并传入 Logger() 的输出参数,如下所示
_logger = Logger(打印机: PrettyPrinter(), 输出: FileOutput());
其中 FileOutput 类负责在文件中写入漂亮的日志,如下所示
class FileOutput extends LogOutput {
FileOutput();
File file;
@override
void init() {
super.init();
file = new File(filePath);
}
@override
void output(OutputEvent event) async {
if (file != null) {
for (var line in event.lines) {
await file.writeAsString("${line.toString()}\n",
mode: FileMode.writeOnlyAppend);
}
} else {
for (var line in event.lines) {
print(line);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3740 次 |
| 最近记录: |