talker_chopper_logger 5.0.1
talker_chopper_logger: ^5.0.1 copied to clipboard
A lightweight, flexible HTTP client logger for Chopper built on the Talker platform, offering advanced exception handling and logging for Dart and Flutter applications.
talker_chopper_logger #
A lightweight, flexible HTTP client logger for Chopper built on the Talker platform, offering advanced exception handling and logging for Dart and Flutter applications.
Preview #
This is how the logs of your http requests will look in the console
For better understanding how it works check Web Demo page
Getting started #
Follow these steps to use this package
Add dependency #
dependencies:
talker_chopper_logger: ^5.0.1
Usage #
Simply include the TalkerChopperLogger in your Chopper client’s interceptors list to enable it.
final client = ChopperClient(
/// ... other chopper settings
interceptors: [
TalkerChopperLogger(
settings: const TalkerChopperLoggerSettings(
printRequestHeaders: true,
printResponseHeaders: true,
printResponseMessage: true,
),
),
],
);
Customization #
To offer extensive functionality, TalkerChopperLoggerSettings provides numerous configuration settings and customization options. You can adjust everything to suit your needs. For example:
Enable or disable HTTP request or response logs #
You can toggle response / request printing and headers including
final client = ChopperClient(
/// ... other chopper settings
interceptors: [
TalkerChopperLogger(
talker: _talker,
settings: const TalkerChopperLoggerSettings(
// All HTTP responses enabled for console logging
printResponseData: true,
// All HTTP requests disabled for console logging
printRequestData: false,
// Response logs including HTTP - headers
printResponseHeaders: true,
// Request logs without HTTP - headers
printRequestHeaders: false,
),
),
],
);
Print HTTP request curl command #
You can print the curl command for the HTTP request in the console. This is useful for debugging and testing purposes.
final client = ChopperClient(
/// ... other chopper settings
interceptors: [
TalkerChopperLogger(
talker: _talker,
settings: const TalkerChopperLoggerSettings(
// 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 = ChopperClient(
/// ... other chopper settings
interceptors: [
TalkerChopperLogger(
talker: _talker,
settings: const TalkerChopperLoggerSettings(
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 TalkerChopperLoggerSettings
TalkerChopperLoggerSettings(
// 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.
TalkerChopperLoggerSettings(
// All http request 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,
)
Using with existing Talker instance #
If your application already uses Talker, simply inject your Talker instance into TalkerChopperLogger so that all logs and errors integrate into your centralized tracking system.
final talker = Talker();
final client = ChopperClient(
/// ... other chopper settings
interceptors: [
TalkerChopperLogger(
talker: talker,
settings: const TalkerChopperLoggerSettings(
printRequestHeaders: true,
printResponseHeaders: true,
printResponseMessage: true,
),
),
],
);
Additional information #
This project is actively being developed and welcomes your pull-requests and issue submissions. Thank you for your support. ❤️