StormyLog class
日志工具类
基于 talker 封装的统一日志工具,提供日志等级过滤、前缀过滤、键名过滤能力。
初始化(可选,默认开箱即用):
LogUtils.init(settings: LogSettings(
filters: [
LevelLogFilter(allowedLevels: {LogLevel.error, LogLevel.warning}),
PrefixLogFilter(prefixes: ['API', 'DB'], excludePrefixes: ['DEBUG*']),
],
));
基本使用:
LogUtils.d('调试信息'); // debug 级别
LogUtils.i('普通信息'); // info 级别
LogUtils.w('警告信息', prefix: 'AUTH'); // warning 级别,带前缀
LogUtils.e('错误信息'); // error 级别
LogUtils.critical('严重错误'); // critical 级别
LogUtils.http('GET /api/users'); // HTTP 请求日志
LogUtils.httpResponse('200 OK /api/users'); // HTTP 响应日志
LogUtils.handle(exception, stackTrace, '上下文'); // 处理异常
过滤器操作:
LogUtils.addFilter(PrefixLogFilter(prefixes: ['API']));
LogUtils.removeAllFilters();
LogUtils.enabled = false; // 全局禁用
获取 Talker 实例(用于高级操作如 TalkerScreen):
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TalkerScreen(talker: LogUtils.talker),
),
);
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
Static Methods
-
addFilter(
LogFilter filter) → void - 添加过滤器
-
clearHistory(
) → void - 清空日志历史
-
critical(
String message, {Map< String, dynamic> ? extra, String? prefix}) → void - 严重错误日志 LogLevel.critical
-
d(
String message, {String? prefix, Map< String, dynamic> ? extra}) → void - 调试日志 LogLevel.debug
-
e(
String message, {StackTrace? stackTrace, Map< String, dynamic> ? extra, String? prefix}) → void - 错误日志 LogLevel.error
-
handle(
Object error, StackTrace stackTrace, [String? message]) → void - 处理异常
-
http(
String message, {Map< String, dynamic> ? extra, String? prefix}) → void - HTTP 请求日志 TalkerKey.httpRequest
-
httpResponse(
String message, {Map< String, dynamic> ? extra, String? prefix}) → void - HTTP 响应日志 TalkerKey.httpResponse
-
i(
String message, {Map< String, dynamic> ? extra, String? prefix}) → void - 详细信息日志 LogLevel.info
-
init(
{LogSettings? settings}) → void - 初始化 LogUtils
-
removeAllFilters(
) → void - 移除所有过滤器
-
w(
String message, {Map< String, dynamic> ? extra, String? prefix}) → void - 警告日志 LogLevel.warning