dio_logger_plus 1.3.0 copy "dio_logger_plus: ^1.3.0" to clipboard
dio_logger_plus: ^1.3.0 copied to clipboard

A powerful and customizable Dio interceptor for Flutter that logs HTTP requests, responses, headers, and errors with pretty-printed JSON. Useful for debugging and development.

DioLoggerPlus #

Pub

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, colored, formatted logs directly in the terminal.


Features #

  • Logs HTTP requests and responses with colored output in the terminal
  • Pretty-prints request/response bodies with ANSI color codes
  • Logs request headers
  • Logs errors with status code and response body
  • Optional compact or indented JSON
  • Fully customizable
  • Supports debug-only logging (enabled via kDebugMode)
  • Supports both terminal output (debugPrint) and DevTools output (dart:developer)

Installation #

Add dio_logger_plus to your pubspec.yaml:

dependencies:
  dio_logger_plus: ^1.3.0

Usage #

Add the interceptor to your Dio instance:

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

final dio = Dio();

dio.interceptors.add(DioLogger(
  request: true,
  requestHeader: true,
  requestBody: true,
  responseBody: true,
  error: true,
  compact: true,
  maxWidth: 90,
  isOnlyDebug: true,
  printToConsole: true, // set to false to use dart:developer log (DevTools only)
));

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 Max width of the log lines (reserved)
isOnlyDebug bool true Enables logging only in debug mode
showTimestamp bool true Shows timestamp in log output
printToConsole bool true Prints colored logs to terminal. Set false for DevTools-only log

Example Output #

When printToConsole: true (default), logs appear in the terminal with colors:

┌─────────────────────────────────────────────────
│  REQUEST [14:32:10.123]
│  GET https://api.example.com/user/123
│  Headers:
│   {
│     "Authorization": "Bearer token123"
│   }
│  Body:
│   {
│     "email": "test@example.com"
│   }
└─────────────────────────────────────────────────

┌─────────────────────────────────────────────────
│  RESPONSE (200) +123ms
│  GET https://api.example.com/user/123
│  Body:
│   {
│     "id": 123,
│     "name": "John Doe"
│   }
└─────────────────────────────────────────────────

┌─────────────────────────────────────────────────
│  ERROR (404)
│  GET https://api.example.com/user/999
│  Message: Not Found
│  Body:
│   {
│     "error": "User not found"
│   }
└─────────────────────────────────────────────────

Request logs are displayed in cyan/yellow, successful responses in green, and errors in red.


Debug-Only Logging #

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

3
likes
160
points
223
downloads

Documentation

API reference

Publisher

verified publisherflutterlab.uz

Weekly Downloads

A powerful and customizable Dio interceptor for Flutter that logs HTTP requests, responses, headers, and errors with pretty-printed JSON. Useful for debugging and development.

Repository (GitHub)
View/report issues

Topics

#dio #http #logging #network

License

Apache-2.0 (license)

Dependencies

dio, flutter

More

Packages that depend on dio_logger_plus