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
import 'package:dio/dio.dart';
import 'package:dio_logging_interceptor_v2/dio_logging_interceptor_v2.dart';
void main() async {
final dio = Dio(
BaseOptions(
baseUrl: 'https://jsonplaceholder.typicode.com',
headers: {
'Authorization': 'Bearer secret_user_token_123',
},
),
);
dio.interceptors.add(
DioLoggingInterceptor(
level: Level.body,
compact: false,
logDuration: true,
logCurl: true,
enableColors: true,
maskedHeaders: ['authorization'],
maskedBodyFields: ['password', 'token'],
ignorePaths: ['/health'],
),
);
print('\n--- 1. Testing GET with JSON Array response ---');
try {
await dio.get('/posts', queryParameters: {'_limit': 2});
} catch (e) {
print('Error: $e');
}
print('\n--- 2. Testing POST with Sensitive Body Masking ---');
try {
await dio.post(
'/posts',
data: {
'title': 'foo',
'body': 'bar',
'userId': 1,
'password': 'mySecretPassword123',
},
);
} catch (e) {
print('Error: $e');
}
}