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
| Level | Constant | Use for |
|---|---|---|
| verbose | XRayLogInspectorLevel.verbose | Fine-grained trace output |
| debug | XRayLogInspectorLevel.debug | Debugging information |
| info | XRayLogInspectorLevel.info | General informational messages |
| warning | XRayLogInspectorLevel.warning | Potentially harmful situations |
| error | XRayLogInspectorLevel.error | Errors 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:
| Field | Type | Description |
|---|---|---|
id | String | Unique entry ID |
message | String | Log message |
level | String | Severity level |
timestamp | DateTime | When the entry was created |
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);
}
}

