efficient_dio_logger 1.8.0
efficient_dio_logger: ^1.8.0 copied to clipboard
Not pretty, but efficient
Efficient Dio Logger / EffLogger #
Dio interceptor: not pretty, but efficient.
For projects using Dio and containing a large number of requests:
- Print large payloads in a copy-friendly format.
- Automatically truncate super long JSON values (image base64, avatar URL...) to avoid console overflow.
适用于使用 Dio 并且包含大量请求的项目:
- 更适合复制和处理大体积请求/响应内容.
- 自动截断超长 JSON value, 避免控制台溢出.
Installation #
dart pub add efficient_dio_logger
Usage #
Default recommendation: use EffDioLogger.
import 'package:dio/dio.dart';
import 'package:efficient_dio_logger/efficient_dio_logger.dart';
void main() {
final dio = Dio();
// Lightweight mode: keep the current compact EffDioLogger output.
dio.interceptors.add(EffDioLogger());
dio.interceptors.add(EffDioLogger(
prettyJson: true,
compact: false,
maxWidth: null,
));
// Legacy-compatible mode: matches EfficientDioLogger(...) switches.
dio.interceptors.add(EffDioLogger.compat(
request: true,
requestHeader: false,
requestBody: false,
responseHeader: false,
responseBody: true,
error: true,
lineWidth: 160,
maxWidth: 320,
compact: true,
prettyJson: true,
enabled: true,
logPrint: print,
filter: (options, args) {
if (options.path.contains('/posts')) {
return false;
}
if (args.isResponse && args.hasUint8ListData) {
return false;
}
return true;
},
));
}
Modes #
EffDioLogger(): lightweight mode. This keeps the existingREQ/RSP/ERRstyle and is the default recommendation for new code.EffDioLogger.compat(): legacy-compatible mode. Use this when migrating fromEfficientDioLogger(...)without changing the old output switches.EfficientDioLogger: deprecated, but still source-compatible. Internally it delegates toEffDioLogger.compat(...)so existing code can upgrade without changing constructor arguments.
Common options #
lineWidthconfigures the divider width used by compat mode.maxWidthconfigures the maximum length of a single request/response value before truncation.compactenablesmaxWidthtruncation.prettyJsonenables indented JSON output for map/list/JSON-string payloads. Default isfalse.logLineBreakcustomizes line breaks forEffDioLoggeroutput.reqExtra,rspExtra,errExtraallow appending custom extra text.
Look Like #

Legacy alias #
typedef PrettyDioLogger = EfficientDioLogger;