request_tracker_logger 1.1.0 copy "request_tracker_logger: ^1.1.0" to clipboard
request_tracker_logger: ^1.1.0 copied to clipboard

A comprehensive request tracking and exception logging library for Flutter applications, inspired by Spring Boot's MDC.

Request Tracker Logger #

A robust request tracking and exception logging library for Flutter applications, inspired by Spring Boot's Mapped Diagnostic Context (MDC).

Features #

  • Contextual Logging: Track logs with unique request IDs across asynchronous boundaries using Dart's Zone.
  • Dio Interceptor & Extensions: Automatically track outgoing HTTP requests, log response times, and capture errors with easy setup.
  • Global Exception Handling: Centralized handling for both Flutter framework errors and uncaught asynchronous errors.
  • Custom Logging Delegates: Easily integrate with Sentry, Firebase Crashlytics, or your own backend.
  • Log Redaction & Cleaning: Automatically mask sensitive data and filter out empty fields for cleaner logs.
  • Debugging Tools: Generate curl commands for failed requests and clean stack traces by filtering framework noise.
  • Global Toggles: Enable or disable logging and exception tracking globally.
  • Lightweight: Optimized to use Stopwatch for timing and dart:developer for efficient logging.

Installation #

Add request_tracker_logger to your pubspec.yaml:

dependencies:
  request_tracker_logger:
    git:
      url: https://github.com/DivyanshVish/request_tracker_logger.git

Usage #

1. Initialize Global Exception Handler #

In your main.dart, initialize the GlobalExceptionHandler before running the app:

import 'package:flutter/material.dart';
import 'package:request_tracker_logger/request_tracker_logger.dart';

void main() {
  GlobalExceptionHandler.initialize();
  runApp(const MyApp());
}

2. Using the Dio Interceptor (via Extension) #

The easiest way to attach tracking is using the .addRequestTracker() extension method:

import 'package:dio/dio.dart';
import 'package:request_tracker_logger/request_tracker_logger.dart';

final dio = Dio();
dio.addRequestTracker(
  redactedFields: ['password', 'auth_token'], // Mask sensitive info
  excludedEndpoints: ['/health', '/metrics'], // Skip logging for these
  maxPayloadLength: 500, // Truncate long payloads
  logCurlOnError: true, // Generate curl for failed requests
  cleanStackTrace: true, // Filter framework noise from errors
);

3. Custom Logging (Integration with Sentry/Firebase) #

Redirect all logs to your preferred analytics service:

RequestLogger.delegate = (message, {level, error, stackTrace, context, extra}) {
  // Example: Forward to Sentry
  // Sentry.captureMessage(message, level: level, extra: {...context, ...?extra});
};

4. Manual Contextual Logging #

You can run code within a specific logging context, including arbitrary MDC keys:

import 'package:request_tracker_logger/request_tracker_logger.dart';

RequestLogger.runWithContext(() {
  RequestLogger.info('Processing payment');
}, 
userId: 'user_123', 
endpoint: '/pay',
extraContext: {'source': 'checkout_page'}
);

Configuration #

Feature Control
Global Logs RequestLogger.enabled = true/false;
Global Exceptions GlobalExceptionHandler.enabled = true/false;

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
160
points
170
downloads

Publisher

verified publisherdivyanshdev.tech

Weekly Downloads

A comprehensive request tracking and exception logging library for Flutter applications, inspired by Spring Boot's MDC.

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, uuid

More

Packages that depend on request_tracker_logger