ts_logger 1.1.2 copy "ts_logger: ^1.1.2" to clipboard
ts_logger: ^1.1.2 copied to clipboard

A package intended for logging API requests and responses in debug console in a simple way.

ts_logger_cover

Designed to enable the user to debug their code and api requests as easily as possible. The package is made so that it is completely safe to use in any environment.( All features will work only if kDebugMode == true )

Features #

  • Log api client requests and responses.
  • Log colorized messages to the console.
  • Log messages to the console with different log levels.
  • Log FlutterError to the console with level and stack trace.

Configuration #

  • You can configure many things with this package. Please check the example below for more details.

Configuration setup #

TsLogger.instance.configure((
  messageLoggerConfig,
  apiLoggerConfig,
) {
    // MessageLoggerConfig
    messageLoggerConfig.example = 'example';
    // ApiLoggerConfig
    apiLoggerConfig.example = 'example';

    // Please check the properties mentioned below for more details.
});
copied to clipboard

MessageLoggerConfig properties #

Property Description Default
logLevels Only the levels you specify using this property will be displayed in the debug console. Useful in the case when, for example, you are only interested in fatal errors, etc. LogLevel.values (All)
messageSpacing The spacing around the message in the console. 0
colorizeLogs If true, the messages will be colorized; otherwise, the text will be white. true
logMessageTime If true, the time when the message was logged will be displayed. true

ApiLoggerConfig properties #

Property Description Default
_maxResponseBodyLengthForPrint The maximum length of the body that will be printed to the console. 1500
messageSpacing The spacing around the message in the console. 2
logRequestQueryParams If true, the query parameters will be displayed in the console. true
logRequestHeaders If true, the request headers will be displayed in the console. false
ignoreRequestHeaders The headers which will be ignored in the console. It does not matter whether letters are uppercase or lowercase. ['Authorization']
logRequestBody If true, the request body will be displayed in the console; otherwise, it will not. true
logRequestStartTime If true, the request start time will be displayed in the console. true
successStatusCodes The status codes that will be considered as successful. [200, 201]
reportInterval Represents the interval for reporting the number of successful and failed requests. null means disable. Duration(minutes: 10)

Usage | Api logging #

Api request and response logging #

  • Log API client requests and responses. This is a basic example of usage.
import 'package:get/get.dart' as g;
import 'package:dio/dio.dart' as d;

final getConnectClient = g.GetConnect();
TsLogger.instance.activateGetConnectLogger(getConnectClient.httpClient);
getConnectClient.get('https://jsonplaceholder.typicode.com/users');

final dioClient = d.Dio();
TsLogger.instance.activateDioLogger(dioClient);
dioClient.get('https://jsonplaceholder.typicode.com/users');
copied to clipboard

Usage | Message logging #

Log messages #

  • Log messages to the console with different log levels. Every log will be unique displayed based on the log level.
TsLogger.instance.logColorizedMessage(...); // Log message with any color
TsLogger.instance.logMessage(...); // Log message for provided log level
TsLogger.instance.logDebug(...); // Log message with debug log level
TsLogger.instance.logInfo(...); // Log message with info log level
TsLogger.instance.logWarning(...); // Log message with warning log level
TsLogger.instance.logError(...); // Log message with error log level
TsLogger.instance.logFatal(...); // Log message with fatal log level
TsLogger.instance.logVerbose(...); // Log message with verbose log level
TsLogger.instance.logCritical(...); // Log message with critical log level
copied to clipboard

FlutterError logging #

  • Log FlutterError to the console with level and stack trace.
FlutterError.onError = (FlutterErrorDetails details) {
  TsLogger.instance.onFlutterError(details);
};
copied to clipboard

Examples #

Message logging example #

image

Api logging example #

image

ToDo #

Support for packages #

  • ✅ Add logging support for get_connect package
  • ✅ Add logging support for dio package
  • ⚙️ Add logging support for http package
13
likes
140
points
199
downloads

Publisher

unverified uploader

Weekly Downloads

2024.10.02 - 2025.04.16

A package intended for logging API requests and responses in debug console in a simple way.

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

dio, flutter, get

More

Packages that depend on ts_logger