talker_http_logger 4.9.2 copy "talker_http_logger: ^4.9.2" to clipboard
talker_http_logger: ^4.9.2 copied to clipboard

Lightweight and customizable http client logger on talker base

talker_http_logger #

Lightweight and customizable http_interceptor client logger on talker base.
Talker - Advanced exception handling and logging for dart/flutter applications 🚀

GitHub codecov Pub License: MIT
talker talker_flutter talker_logger

Preview #

This is how the logs of your http requests will look in the console

Getting started #

Follow these steps to use this package

Add dependency #

dependencies:
  talker_http_logger: ^4.9.2

Usage #

Just add TalkerHttpLogger to your InterceptedClient instance and it will work

import 'package:http_interceptor/http_interceptor.dart';
import 'package:talker_http_logger/talker_http_logger.dart';

void main() async {
  final client = InterceptedClient.build(interceptors: [
    TalkerHttpLogger(
      settings: const TalkerHttpLoggerSettings(
        printRequestHeaders: true,
        printResponseHeaders: true,
        printResponseMessage: true,
      ),
    ),
  ]);

  await client.get("https://google.com".toUri());
}

Using with Talker #

You can add your talker instance for TalkerHttpLogger if your app already uses Talker.

In this case, all logs and errors will fall into your unified tracking system

import 'package:http_interceptor/http_interceptor.dart';
import 'package:talker_http_logger/talker_http_logger.dart';

void main() async {
  final _talker = Talker();
  final client = InterceptedClient.build(
    /// ... other settings
    interceptors: [
      TalkerHttpLogger(
        /// ... other Talker HTTP Logger settings
        talker: _talker,
      ),
    ]
  );

  await client.get("https://google.com".toUri());

You can print the curl command for the HTTP request in the console. This is useful for debugging and testing purposes.

final client = InterceptedClient.build(
  /// ... other settings
  interceptors: [
    TalkerHttpLogger(
      talker: _talker,
      settings: const TalkerHttpLoggerSettings(
        // Print curl command for HTTP request
        printRequestCurl: true,
      ),
    ),
  ],
);

Hiding sensitive HTTP request headers #

You can hide sensitive HTTP request headers such as Authorization or Cookie in the console logs. This is useful for security purposes.

final client = InterceptedClient(
  /// ... other settings
  interceptors: [
    TalkerHttpLogger(
      talker: _talker,
      settings: const TalkerHttpLoggerSettings(
        printRequestHeaders: true,
        printResponseHeaders: true,
        // Hide sensitive HTTP request headers
        hiddenHeaders: {
          'authorization',
          'cookie',
        },
      ),
    ),
  ],
);

Change HTTP logs colors #

Customize your HTTP log colors by defining specific colors for requests, responses, and errors in TalkerHttpLoggerSettings

TalkerHttpLoggerSettings(
  // Blue HTTP requests logs in console
  requestPen: AnsiPen()..blue(),
  // Green HTTP responses logs in console
  responsePen: AnsiPen()..green(),
  // Error HTTP logs in console
  errorPen: AnsiPen()..red(),
);

Filter HTTP logs #

For instance, if your app includes private functionality that you prefer not to log with talker, you can apply filters.

TalkerHttpLoggerSettings(
  // All http requests without "/secure" in path will be printed in console 
  requestFilter: (Request request) => !request.url.path.contains('/secure'),
  // All http responses with status codes different than 301 will be printed in console 
  responseFilter: (Response response) => response.statusCode != 301,
)

Additional information #

The project is under development and ready for your pull-requests and issues 👍
Thank you for support ❤️

9
likes
160
points
9.62k
downloads

Publisher

verified publisherfrezycode.com

Weekly Downloads

Lightweight and customizable http client logger on talker base

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

equatable, http_interceptor, meta, talker

More

Packages that depend on talker_http_logger