riverpod_dev_logger 0.0.8 copy "riverpod_dev_logger: ^0.0.8" to clipboard
riverpod_dev_logger: ^0.0.8 copied to clipboard

A developer-focused logging package for Riverpod with automatic provider context detection using Dart Zones. Supports Riverpod 2.0+.

riverpod_dev_logger #

pub package license GitHub stars

A developer-focused logging package for Riverpod 2.0+ that automatically detects and logs Provider execution context using Dart Zones.

Features #

  • Automatic Provider Context Detection: No more manual tags! Logs automatically include the name and type of the provider that emitted them via Dart Zones.
  • Riverpod 2.0+ Ready: Built explicitly for the latest Riverpod features and patterns, with support for 2.x and 3.x.
  • Structured Console Output: Beautifully organized logs with level, provider info, dependencies, and extra metadata.
  • State Diff Tracking: Automatically detect and log state changes. Visualizes additions, removals, and modifications for both primitives and complex collections.
  • Hierarchical Loggers: Use .bind() to create child loggers with additional context like userId or requestId.
  • Extensible Formatters: Easily customize how logs are printed or sent to remote services.

Installation #

Add riverpod_dev_logger to your pubspec.yaml:

dependencies:
  riverpod_dev_logger: ^0.0.8

Setup #

Initialize the logger and add the observer to your ProviderContainer:

import 'package:riverpod/riverpod.dart';
import 'package:riverpod_dev_logger/riverpod_dev_logger.dart';

void main() {
  RiverpodDevLogger.configure(
    level: LogLevel.debug,
    enableContextDetection: true,
    enableStateDiff: true, // Enabled by default
  );

  final container = ProviderContainer(
    observers: [
      RiverpodLoggerObserver(),
    ],
  );

  // ...
}

Usage #

In Providers #

Use the ref.logger extension to log within functional or class-based providers:

final counterProvider = StateProvider<int>((ref) {
  ref.logger.info('Initializing counter');
  return 0;
}, name: 'CounterProvider');

Output: [INFO] [Provider:CounterProvider] [Dependencies:none] Initializing counter

Child Loggers #

Bind extra context like user IDs or session IDs:

final authenticatedLogger = ref.logger.bind(userId: 'user_123');
authenticatedLogger.info('User action performed');

State Diff Tracking #

The logger automatically detects changes when state is updated. Works out-of-the-box for:

  • Primitive types (int, String, bool, etc.)
  • Collections (List, Map, Set)
  • Custom objects (supports Freezed, json_serializable, and Equatable via toJson())

Output Example:

[INFO] [Provider:TodoProvider] State changed:
  ~ name: 'Old Task' → 'New Task'
  + priority: 'high'

License #

MIT License - see the LICENSE file for details.

0
likes
150
points
161
downloads

Publisher

unverified uploader

Weekly Downloads

A developer-focused logging package for Riverpod with automatic provider context detection using Dart Zones. Supports Riverpod 2.0+.

Repository (GitHub)
View/report issues

Topics

#riverpod #logging #debug #context

Documentation

API reference

License

MIT (license)

Dependencies

meta, riverpod

More

Packages that depend on riverpod_dev_logger