Log Inspection

Capture structured log entries with levels for real-time inspection.

XRayLogInspector captures structured log entries with severity levels, storing them in memory for real-time inspection via the remote UI.

Setup

import 'package:xray_inspector/xray_inspector.dart';

final logInspector = XRayLogInspector();

// Optional: custom title shown in the remote UI
final logInspector = XRayLogInspector(title: 'App Logs');

Logging messages

logInspector.verbose('Detailed trace message');
logInspector.debug('Debug information');
logInspector.info('User signed in');
logInspector.warning('Deprecated API used');
logInspector.error('Failed to load data');

// Or with an explicit level
logInspector.log('Custom message', level: XRayLogInspectorLevel.info);

Log levels

LevelConstantUse for
verboseXRayLogInspectorLevel.verboseFine-grained trace output
debugXRayLogInspectorLevel.debugDebugging information
infoXRayLogInspectorLevel.infoGeneral informational messages
warningXRayLogInspectorLevel.warningPotentially harmful situations
errorXRayLogInspectorLevel.errorErrors and exceptions

Accessing log entries

// Snapshot of all entries
final entries = logInspector.entries;

// Reactive — rebuilds widget when entries change
ValueListenableBuilder<List<XRayLogInspectorEntry>>(
  valueListenable: logInspector.entriesNotifier,
  builder: (context, entries, _) {
    return Text('${entries.length} log entries');
  },
);

Log entry model

Each entry is an XRayLogInspectorEntry with:

FieldTypeDescription
idStringUnique entry ID
messageStringLog message
levelStringSeverity level
timestampDateTimeWhen the entry was created

Clearing entries

logInspector.clear();

Integrating with existing logging

Route your existing logging through the inspector:

// Example: wrapping a logger
class AppLogger {
  final XRayLogInspector _inspector;

  AppLogger(this._inspector);

  void info(String message) {
    debugPrint('[INFO] $message');
    _inspector.info(message);
  }

  void error(String message, [Object? error]) {
    debugPrint('[ERROR] $message${error != null ? ': $error' : ''}');
    _inspector.error(error != null ? '$message: $error' : message);
  }
}

Multiple log inspectors

final appLogs = XRayLogInspector(title: 'App');
final networkLogs = XRayLogInspector(title: 'Network');

Both will appear as separate tabs in the remote UI.