Skip to main content

flutter_api_logger 1.1.0 copy "flutter_api_logger: ^1.1.0" to clipboard
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 #

pub package CI license: MIT

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 http client's bodies), form bodies and URLs.
  • The package no longer depends on Flutter or rxdart.

Contributing #

See CONTRIBUTING.md. Licensed under MIT.

1
likes
160
points
101
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Secure API request & response logger for http and dio. Masks tokens and passwords, silent in release builds, optional cURL output. Pure Dart.

Repository (GitHub)
View/report issues
Contributing

Topics

#logging #http #dio #networking

License

MIT (license)

Dependencies

dio, http

More

Packages that depend on flutter_api_logger