talker_http_logger 4.9.1
talker_http_logger: ^4.9.1 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 🚀
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.1
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());
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 = 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 ❤️