flutter_api_logger 1.1.0
flutter_api_logger: ^1.1.0 copied to clipboard
Secure API request & response logger for http and dio. Masks tokens and passwords, silent in release builds, optional cURL output. Pure Dart.
flutter_api_logger #
A secure API request & response logger for http and dio. One
package, one config, same output for both clients. Pure Dart, so it also works
in server and CLI code.
Features #
- ๐ Secure by default: tokens, passwords, cookies and API keys are masked in headers, nested JSON, JSON strings, form bodies and URL query parameters.
- ๐ก๏ธ Silent in release builds unless you set
enableInRelease: true. - ๐ Request/response correlation: every pair shares an id (
#3), so concurrent calls to the same URL never get mixed up. - ๐งพ Optional masked cURL output to reproduce a call in a terminal or Postman.
- ๐ฆ Understands
FormData/ multipart (field values masked, files summarized) and binary bodies. - ๐ UTF-8 safe (Bangla and other non-ASCII responses stay readable).
- โก Doesn't buffer binary or large downloads when it won't log the body.
- ๐ Custom output sink and URL exclusions.
Install #
dependencies:
flutter_api_logger: ^1.1.0
Usage #
dio #
final dio = Dio();
dio.interceptors.add(ApiLoggerDioInterceptor());
http #
final client = ApiLoggerHttpClient();
final response = await client.get(Uri.parse('https://example.com/users/1'));
client.close();
Configure #
const config = ApiLoggerConfig(
showCurl: true,
showResponseHeaders: true,
maskedKeys: ['token', 'password', 'authorization', 'ssn'],
excludeUrlPatterns: ['/health', 'analytics'],
);
dio.interceptors.add(ApiLoggerDioInterceptor(config: config));
final client = ApiLoggerHttpClient(config: config);
| Option | Default | Description |
|---|---|---|
enableLog |
true |
Master switch. |
enableInRelease |
false |
Allow logging in release builds. |
showHeaders |
true |
Request headers. |
showResponseHeaders |
false |
Response headers. |
showRequestBody / showResponseBody |
true |
Bodies. |
showCurl |
false |
Masked cURL command per request. |
maskedKeys |
token, password, authorization, secret, key, cookie, otp, credential | Case-insensitive substring match. |
maskValue |
*** |
Replacement text. |
maxBodyLength |
10000 |
Truncate long bodies. |
logColor |
true |
ANSI colors. |
excludeUrlPatterns |
[] |
Skip URLs containing any of these. |
output |
dart:developer log |
Custom sink, e.g. print or your own logger. |
Example output #
โโโโโโโโโ API REQUEST #1 โโโโโโโโ
โ POST https://api.example.com/login?token=***
โ Headers: {Authorization: ***, Accept: application/json}
โ Body: {
โ "user": "bob",
โ "password": "***"
โ }
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโ API RESPONSE #1 โโโโโโโโ
โ POST https://api.example.com/login?token=***
โ โฑ 312 ms | Status: 200
โ {
โ "token": "***"
โ }
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Upgrading to 1.1 #
- Release builds no longer log unless
enableInRelease: true(this is what 1.0 documented, but it was not enforced). - Masking now also covers JSON strings (the
httpclient's bodies), form bodies and URLs. - The package no longer depends on Flutter or
rxdart.
Contributing #
See CONTRIBUTING.md. Licensed under MIT.