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,
response: true,
requestHeader: false,
requestBody: false,
responseHeader: false,
responseBody: true,
error: true,
lineWidth: 160,
maxWidth: 320,
compact: true,
prettyJson: true,
objectEncoder: (object) {
if (object is User) {
return {'id': object.id, 'name': object.name};
}
return defaultLogObjectEncoder(object);
},
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.response: falsecompletely disables successful response logs without affecting error logs.responseBody: falseonly hides the response body.maxWidthconfigures the maximum length of a single string before truncation.compactenablesmaxWidthstring truncation.prettyJsonenables indented output for structured data without changing payload types. Top-level strings are always logged as text. Default isfalse.objectEncoderconverts custom objects into structured log values. It defaults todefaultLogObjectEncoder.logLineBreakcustomizes line breaks forEffDioLoggeroutput.reqExtra,rspExtra,errExtraallow appending custom extra text.
Data fidelity and custom objects
Version 2 preserves JSON-native value types. Numbers, booleans, and null values
are no longer converted to strings. Maps and lists remain JSON-encoded, while a
top-level request, successful response, or error response string is logged
directly as text without JSON outer quotes or escaping. prettyJson formats
structured data only and does not parse JSON-looking strings.
Explicit string controls still apply: compact and maxWidth can truncate a
top-level string, and logLineBreak replaces its newline characters together
with the rest of the emitted log.
Non-string map keys cannot be represented by a JSON object without changing or
colliding keys. They are logged as a typed entries list instead. Non-finite
doubles, sets, circular references, and non-JSON objects also use an explicit
$type marker.
The default object encoder supports FormData, MultipartFile, DateTime,
Uri, Duration, BigInt, RegExp, Enum, Type, Error, Exception,
StackTrace, and Symbol. Unknown objects fall back to a typed string
representation.
To add an application object, return a JSON-compatible value and delegate other objects to the built-in encoder:
final logger = EffDioLogger(
objectEncoder: (object) {
if (object is User) {
return {
'id': object.id,
'name': object.name,
'createdAt': object.createdAt,
};
}
return defaultLogObjectEncoder(object);
},
);
Values returned by objectEncoder are normalized recursively, so nested custom
objects and configured string truncation continue to work.
To place request and response loggers on opposite sides of an interceptor:
final requestLogger = EffDioLogger(
response: false,
error: false,
);
final responseLogger = EffDioLogger(request: false);
dio.interceptors.addAll([
requestLogger,
encryptionInterceptor,
responseLogger,
]);
Look Like

Legacy alias
typedef PrettyDioLogger = EfficientDioLogger;