pd_log 0.6.1
pd_log: ^0.6.1 copied to clipboard
Cross-platform logging plugin for Flutter with buffered native file logging.
pd_log #
轻量、跨平台的 Flutter 日志插件,支持原生文件缓冲写入与统一 Dart API。
特性概览 #
- 级别日志与样式:
PDLog.v/d/i/w/e、JSON 美化打印、ANSI 样式。 - 原生文件缓冲:移动/桌面平台支持写线程缓冲与定时/阈值刷新。
- 文件查询与维护:列出/删除日志、滚动清理、按年/月/日组织。
- 元数据追踪:事件账本(NDJSON)与快照(JSON)自动维护。
- 统一跨平台:Web 控制台输出(不执行文件写入),接口一致。
安装与快速使用 #
dependencies:
pd_log: ^0.6.1
import 'package:pd_log/pd_log.dart';
void main() {
PDLog.configure(const PDLogConfig(
minLevel: LogLevel.debug,
useNative: true,
nativeFileLoggingEnabled: true,
));
PDLog.i('pd_log is ready');
}
关键 API(精选) #
- 输出日志:
PDLog.v/d/i/w/e(Object? message, {String? tag}) - 刷新缓冲:
PDLog.flushNativeLogs() - 查询日志:
PDLog.listLogFiles(...)、listLogFilesByYear(...)、listLogFilesByYearMonth(...) - 文件路径:
PDLog.logFilePathIfExists(DateTime date) - 读取文件:
PDLog.readLogFileContent(String path)(平台文件读取) - 元数据查看:
PDLog.metaLedgerContent()、PDLog.metaSummaryContent() - 目录结构:
PDLog.fileTreeString({int maxDepth = 6})
文档 #
详细使用说明、注意事项与最佳实践已迁移至文档模块:
- 查看文档目录:
doc/README.md - 入门与配置、文件结构与滚动清理、查询与分页、元数据与历史、跨平台差异、样式与美化等
示例项目 #
最小示例位于 example/ 目录,可直接运行 flutter run。
许可证 #
MIT(见根目录 LICENSE)。