dio_logging_interceptor_v2 1.1.0
dio_logging_interceptor_v2: ^1.1.0 copied to clipboard
A Dio interceptor which logs HTTP request and response data without truncation
dio_logging_interceptor_v2 #
A simple and robust Dio interceptor which logs HTTP request and response data without truncation on Android/iOS/Flutter consoles.
Features #
- No Truncation: Automatically splits long single-line or multi-line logs into chunks so your Android Logcat, iOS Console, or IDE never cuts off long JSON, base64, or tokens.
- Comprehensive Data Formats: Supports
Map,List(JSON Arrays),FormData(multipart fields & file details),Binary/Bytes, andString. - Formatted Query Parameters: Optionally logs
queryParametersin formatted key-value / JSON map (logQueryParams: true). - Rich Error Diagnostics: Detailed error logs including
DioExceptionType, error message, and optionalstackTrace. - Request Duration: Logs response duration in milliseconds (e.g.
[DIO]<-- 200 OK (154ms)). - Security & Masking: Automatically masks sensitive headers (
Authorization,Cookie,Token) and sensitive JSON body/query fields (password,pin,otp,cvv, etc.). - cURL Command Generator: Optionally prints ready-to-use
curlcommands for quick sharing and backend debugging. - Endpoint Filtering: Ignore logs for heartbeat, polling, or analytics endpoints using
ignorePathsor customfiltercallbacks. - ANSI Colors: Optional terminal color highlighting for requests (cyan), responses (green), and errors (red).
Usage #
import 'package:dio/dio.dart';
import 'package:dio_logging_interceptor_v2/dio_logging_interceptor_v2.dart';
final dio = Dio();
dio.interceptors.add(
DioLoggingInterceptor(
level: Level.body,
compact: false,
tag: '[DIO]', // Custom tag prefix
logDuration: true, // Display response time in ms
logCurl: true, // Generate copy-pasteable cURL command
logQueryParams: true, // Format and print query parameters map
logErrorDetails: true, // Print DioExceptionType & detailed message
logStackTrace: false, // Print stackTrace on error
enableColors: true, // Colorize logs with ANSI codes
maxChunkSize: 800, // Maximum characters per print line before chunking
maskedHeaders: ['authorization', 'cookie', 'token'],
maskedBodyFields: ['password', 'pin', 'token', 'otp'],
ignorePaths: ['/health', '/ping'],
),
);
Sample output #
[DIO]--> POST https://example.com/api/login
[DIO][CURL] curl -X POST "https://example.com/api/login" -H "authorization: ***" -d '{"email":"user@example.com","password":"***"}'
[DIO][HEADER]authorization:***
[DIO][HEADER]content-type:application/json; charset=utf-8
[DIO][DATA]{
[DIO][DATA] "email": "user@example.com",
[DIO][DATA] "password": "***"
[DIO][DATA]}
[DIO]--> END POST
[DIO]<-- 200 OK (85ms)
[DIO][HEADER]content-length:[249]
[DIO][HEADER]content-type:[application/json; charset=utf-8]
[DIO][DATA]{
[DIO][DATA] "token": "***",
[DIO][DATA] "user": {
[DIO][DATA] "id": "1001",
[DIO][DATA] "name": "John"
[DIO][DATA] }
[DIO][DATA]}
[DIO]<-- END HTTP