Logger class

A robust logging framework for Reactiv

Features:

  • Multiple log levels (verbose, debug, info, warning, error, wtf)
  • Pretty JSON formatting
  • Stack trace support
  • Configurable output
  • File/line number tracking
  • Custom handlers
  • Production/Development modes
  • Performance timing
  • Table formatting

Example:

// Configure logger
Logger.config = LoggerConfig.development;

// Basic logging
Logger.info('User logged in');
Logger.error('Failed to fetch data');

// With custom tag
Logger.d('Debug message', tag: 'MyFeature');

// Log JSON
Logger.json({'user': 'John', 'age': 30});

// Log with stack trace
Logger.error('Something went wrong', error: exception, stackTrace: stack);

// Measure performance
final result = await Logger.timed(() => fetchData(), label: 'API Call');

// Log table
Logger.table([
  {'name': 'John', 'age': 30},
  {'name': 'Jane', 'age': 25},
]);

Constructors

Logger()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

config LoggerConfig
Current configuration
getter/setter pair
enabled bool
Backward compatibility: enable/disable logging
getter/setter pair

Static Methods

d(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Shorthand for debug
debug(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Debug logging (diagnostic information)
divider({String tag = 'Reactiv', String char = '─', int length = 80}) → void
Log a divider line
e(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Shorthand for error
error(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Error logging (error conditions)
Log a header with borders
i(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Shorthand for info
info(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Info logging (general information)
json(Object? object, {String tag = 'Reactiv', LogLevel level = LogLevel.debug}) → void
Log a JSON object with pretty formatting
table(List<Map<String, dynamic>> data, {String tag = 'Reactiv'}) → void
Log a table (list of maps)
timed<T>(Future<T> function(), {String? label, String tag = 'Reactiv'}) Future<T>
Log execution time of a function
timedSync<T>(T function(), {String? label, String tag = 'Reactiv'}) → T
Log execution time of a synchronous function
v(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Shorthand for verbose
verbose(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Verbose logging (detailed information)
w(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Shorthand for warning
warn(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
Warning logging (potential issues)
wtf(dynamic message, {String tag = 'Reactiv', Object? error, StackTrace? stackTrace}) → void
WTF logging (What a Terrible Failure - should never happen)