-
Notifications
You must be signed in to change notification settings - Fork 3
Log Viewer
The Log Viewer automatically captures logs from multiple sources with zero configuration.
日志查看器自动从多个来源捕获日志,无需配置。
| Source | Capture Method |
|---|---|
print() |
Zone specification override / Zone 规范覆盖 |
debugPrint() |
debugPrint override / debugPrint 覆盖 |
| Flutter errors | runZonedGuarded / runZonedGuarded 捕获 |
| Unhandled exceptions | runZonedGuarded / runZonedGuarded 捕获 |
| Third-party libraries | Via print() capture / 通过 print() 捕获 |
| Level | Abbreviation | Color | Description |
|---|---|---|---|
| Verbose | V | Gray | Detailed information / 详细信息 |
| Debug | D | Blue | Debug information / 调试信息 |
| Info | I | Green | General information / 一般信息 |
| Warning | W | Orange | Warning messages / 警告信息 |
| Error | E | Red | Error messages / 错误信息 |
Third-party library logs are categorized as Info level.
第三方日志库的日志统一归类为 Info 级别。
- All: Show all logs / 显示所有日志
- V / D / I / W / E: Filter by level / 按级别过滤
- Single-select mode / 单选模式
- Level badge with color / 带颜色的级别徽章
- Timestamp display / 时间戳显示
- Tag display (if available) / 标签显示(如有)
- Error/warning rows have subtle background tint / 错误/警告行有淡色背景
- Left border color indicates level / 左侧边框颜色表示级别
- Fuzzy search by message content or tag / 按消息内容或标签模糊搜索
- Combined with level filter / 可与级别过滤组合使用
Quick shorthand (recommended) / 简化写法(推荐) — available since v1.1.2 / v1.1.2 起可用:
InspectorLog.v('Verbose message / 详细消息');
InspectorLog.d('Debug message / 调试消息');
InspectorLog.i('Info message / 信息消息');
InspectorLog.w('Warning message / 警告消息');
InspectorLog.e('Error message / 错误消息');
// With tag / 带标签
InspectorLog.i('User logged in', tag: 'Auth');Full form / 完整写法:
InspectorLogInterceptor.instance.verbose('Verbose message / 详细消息');
InspectorLogInterceptor.instance.debug('Debug message / 调试消息');
InspectorLogInterceptor.instance.info('Info message / 信息消息');
InspectorLogInterceptor.instance.warning('Warning message / 警告消息');
InspectorLogInterceptor.instance.error('Error message / 错误消息');
// With tag / 带标签
InspectorLogInterceptor.instance.info('User logged in', tag: 'Auth');InspectorLog is a static wrapper around InspectorLogInterceptor.instance for shorter log calls.
InspectorLog 是 InspectorLogInterceptor.instance 的静态包装,用于更简短的日志调用。
No configuration needed. Any library using print() or debugPrint() is automatically captured.
无需配置。任何使用 print() 或 debugPrint() 的库都会被自动捕获。
To forward inspector logs to your third-party logger:
将检查器日志转发到第三方日志库:
import 'package:logger/logger.dart';
final logger = Logger();
InspectorLogInterceptor.instance.onLogCaptured = (entry) {
logger.log(
_mapLogLevel(entry.level),
'${entry.tag != null ? '[${entry.tag}] ' : ''}${entry.message}',
);
};Note: Do NOT call logging methods inside
onLogCaptured, as this will cause infinite recursion. 注意:不要在onLogCaptured内部调用日志方法,否则会导致无限递归。
If using runAppWithInspector(), the log interceptor starts automatically. Otherwise:
如果使用 runAppWithInspector(),日志拦截器会自动启动。否则:
InspectorLogInterceptor.instance.start();