DioLoggerPlus

DioLoggerPlus is a custom logging interceptor for the Dio HTTP client in Flutter. It helps developers easily debug HTTP requests and responses by printing clean, formatted logs in the console.


✨ Features

  • βœ… Logs HTTP requests and responses
  • πŸ“¦ Pretty-prints request/response bodies
  • πŸ”Έ Logs request headers
  • ❌ Logs errors with status and response body
  • 🧩 Optional compact or indented JSON
  • πŸ›  Fully customizable
  • πŸ” Supports debug-only logging (enabled via kDebugMode)

πŸ“¦ Installation

Add dio to your pubspec.yaml:

dependencies:
  dio: ^5.0.0

Then copy the DioLoggerPlus class into your project.

πŸš€ Usage

Add the interceptor to your Dio instance:

import 'package:dio/dio.dart';
import 'dio_logger_plus.dart'; // import your class

final dio = Dio();

dio.interceptors.add(DioLoggerPlus(
  request: true,
  requestHeader: true,
  requestBody: true,
  responseBody: true,
  error: true,
  compact: true,
  maxWidth: 90,
  isOnlyDebug: true,
));

βš™οΈ Configuration Options

Parameter Type Default Description
request bool true Logs HTTP method and URL
requestHeader bool true Logs request headers
requestBody bool true Logs request body
responseBody bool true Logs response body
error bool true Logs errors and error bodies
compact bool true Minimized JSON indentation
maxWidth int 90 (Reserved) Max width of the log lines
isOnlyDebug bool true Enables logging only in debug mode

πŸ§ͺ Example Output

β”Œβ”€β”€β”€β”€β”€β”€β”€ πŸ“€ REQUEST [2025-06-11 14:32:10] ───────
β”‚ ➑️ GET https://api.example.com/user/123
β”‚ πŸ”Έ Headers:
β”‚ {
β”‚   "Authorization": "Bearer token123"
β”‚ }
β”‚ πŸ“¦ Body:
β”‚ {
β”‚   "email": "test@example.com"
β”‚ }
└───────────────────────────────────────────────

β”Œβ”€β”€β”€β”€β”€β”€ βœ… RESPONSE (200 OK) [+123ms] ──────────
β”‚ URL: https://api.example.com/user/123
β”‚ πŸ“¦ Body:
β”‚ {
β”‚   "id": 123,
β”‚   "name": "John Doe"
β”‚ }
└───────────────────────────────────────────────

πŸ” Debug-Only Logging

By default, logs are shown only in debug mode (kDebugMode). To enable logs in release mode, set isOnlyDebug: false.

Libraries

dio_logger_plus