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 existing REQ/RSP/ERR style and is the default recommendation for new code.
  • EffDioLogger.compat(): legacy-compatible mode. Use this when migrating from EfficientDioLogger(...) without changing the old output switches.
  • EfficientDioLogger: deprecated, but still source-compatible. Internally it delegates to EffDioLogger.compat(...) so existing code can upgrade without changing constructor arguments.

Common options

  • lineWidth configures the divider width used by compat mode.
  • maxWidth configures the maximum length of a single request/response value before truncation.
  • compact enables maxWidth truncation.
  • prettyJson enables indented JSON output for map/list/JSON-string payloads. Default is false.
  • logLineBreak customizes line breaks for EffDioLogger output.
  • reqExtra, rspExtra, errExtra allow appending custom extra text.

Look Like

img.png

Legacy alias

typedef PrettyDioLogger = EfficientDioLogger;