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 Darts's Zone.
  • Dio Interceptor: Automatically track outgoing HTTP requests, log response times, and capture errors.
  • Global Exception Handling: Centralized handling for both Flutter framework errors and uncaught asynchronous errors.
  • Zero Configuration: Easy to set up and start tracking.

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

Attach the RequestTrackingInterceptor to your Dio instance:

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

final dio = Dio();
dio.interceptors.add(RequestTrackingInterceptor());

3. Manual Contextual Logging

You can run code within a specific logging context:

import 'package:request_tracker_logger/request_tracker_logger.dart';

RequestLogger.runWithContext(() {
  RequestLogger.info('Processing payment');
  // All logs inside this block will share the same UUID
}, userId: 'user_123', endpoint: '/pay');

License

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