net_logger

A lightweight local network request logging client package for Flutter and Dart applications. It intercepts HTTP requests, responses, and errors, and streams them in real-time to the companion app net_logger_viewer for easy local debugging and analysis.

Features

  • 🚀 Real-Time Streaming: Outgoing and incoming HTTP logs are streamed instantly to your local dashboard.
  • 📦 Dio Interceptor: Native support for Dio clients via NetLoggerInterceptor.
  • 🔗 http Client Wrapper: Support for standard Dart http packages via NetLoggerHttpClient.
  • 🔍 Detailed Telemetry: Captures methods, status codes, request/response headers, bodies, path parameters, execution duration, and stack traces on error.
  • ⚙️ Robust & Non-blocking: Logs are transmitted asynchronously in the background. Network issues, timeouts, or exceptions in sending telemetry are handled silently so they never disrupt your application's user experience.

Installation

Add net_logger to your project's pubspec.yaml dependencies:

dependencies:
  net_logger: ^1.0.3

Run pub get in your terminal:

flutter pub get

Usage

1. Integrating with Dio

To log requests from a Dio instance, register NetLoggerInterceptor to its interceptors chain:

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

void main() {
  final dio = Dio();

  dio.interceptors.add(
    NetLoggerInterceptor(
      appName: 'Flutter Client App', // Identifies this app in the viewer
      // serverUrl is optional (defaults to localhost or 10.0.2.2 on Android emulator)
      // serverUrl: 'http://localhost:8080', 
    ),
  );

  // Trigger requests normally
  dio.get('https://jsonplaceholder.typicode.com/posts/1');
}

2. Integrating with the standard http package

For the http package, wrap your standard client inside a NetLoggerHttpClient:

import 'package:http/http.dart' as http;
import 'package:net_logger/net_logger.dart';

Future<void> makeRequest() async {
  // Wrap standard http.Client
  final client = NetLoggerHttpClient(
    http.Client(),
    appName: 'Flutter Client App',
    // serverUrl: 'http://localhost:8080', // Optional
  );

  try {
    // Use it like a standard http client
    final response = await client.get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1'));
    print('Response status: ${response.statusCode}');
  } finally {
    client.close(); // Closes the underlying client
  }
}

Configuration Options

Both NetLoggerInterceptor and NetLoggerHttpClient accept the following configuration parameters:

Parameter Type Default Value Description
appName String (Required) Identifies this app instance in the dashboard (useful for filtering multi-client logs).
serverUrl String? Platform.isAndroid ? 'http://10.0.2.2:8080' : 'http://localhost:8080' The URL where the net_logger_viewer companion app is running.
timeout Duration? null Optional duration after which the request is marked as timed out locally.
enableConsoleLogs bool false When true, prints clean request, response, error, and timeout details directly to the local debug console (including query parameters and multipart request bodies).

Companion Dashboard App

To view the logged requests, run the companion application net_logger_viewer located in the root repository. By default, it opens a local HTTP server on port 8080 and displays a premium web/desktop dashboard that lets you search and filter logs by status code, HTTP method, app origin, and timestamps.

Libraries

net_logger
A local API request logger library for Flutter and Dart applications.