FileLogOutput class
文件输出器:将日志逐行追加写入指定文件,超限自动轮转归档。
行为对齐 LogStorage 的文件面:
- 惰性打开持久化 IOSink(首条 output 时才打开;父目录不存在时 递归创建);初始字节数取磁盘已有大小,续写不清空。
- 内存跟踪已写字节数(
utf8.encode长度累加),不逐行查磁盘。 - 超过 maxFileSize 时轮转:flush + close 旧流 → 当前文件重命名为
同目录归档文件(文件名加
_yyyy-MM-dd_HHMMss时间戳后缀,无扩展名 路径不拼悬空点)→ 删除超出 maxFileCount 的最旧归档 → 重开新文件。 - 删旧只匹配本文件基名的
基名_前缀归档,同目录其它文件不受影响。 - dispose 时 flush + close;dispose 后再 output 直接忽略。
- 无周期 flush(与 LogStorage 的定时 flush 不同):仅在轮转与 dispose 时刷盘,进程异常终止可能丢失尾部仍在 IOSink 缓冲的日志。
写入行格式为 LogEntry.toString——含 error / stackTrace / extra 的条目
占多行,非按行解析格式(需机器解析请用 LogStorage 的 JSON 行)。
文件输出不是控制台输出(isConsole 为 false),不受
LogEntry.suppressConsole 的条目级压制影响。
⚠️ 本文件引入 dart:io 后,整个 log_output.dart(含
ConsoleLogOutput / BatchLogOutput)在 web 平台不可编译。
Constructors
- FileLogOutput({required String filePath, int maxFileSize = 10 * 1024 * 1024, int maxFileCount = 10})
Properties
- filePath → String
-
输出文件路径(父目录不存在时自动递归创建)。
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isConsole → bool
-
是否为控制台类输出器。
no setterinherited
- maxFileCount → int
-
保留的文件数量上限(活跃文件 + 归档合计)。
final
- maxFileSize → int
-
单文件最大字节数,超出则轮转。
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → Future< void> -
销毁输出器(如 flush / 关闭流)。默认空实现。
override
-
initialize(
) → Future< void> -
初始化输出器(如打开连接 / 文件)。默认空实现。
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
output(
LogEntry entry) → Future< void> -
输出一条日志条目。
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited