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

Custom logging interceptor for the Dio

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 β†’ POST https://api.example.com/login
πŸ”Έ Headers: {"Content-Type":"application/json"}
πŸ“¦ Body:
{
"email": "test@example.com",
"password": "123456"
}

βœ… RESPONSE:https://api.example.com/login:
{
"token": "abc123xyz"
}

❌ ERROR ← https://api.example.com/login
⛔️ Message: Unauthorized
πŸ“› Error Body:
{
"error": "Invalid credentials"
}

πŸ” Debug-Only Logging

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

3
likes
0
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

Custom logging interceptor for the Dio

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter

More

Packages that depend on dio_logger_plus