JStructuredLogger class
Structured logger that outputs JSON-formatted log messages.
This logger provides:
- Structured JSON output for easier parsing and analysis
- Log levels (trace, debug, info, warn, error)
- Timestamps for all log entries
- Context propagation through correlation IDs
- PII handling guidance (user must redact sensitive data)
Example usage:
void main() {
final logger = JStructuredLogger(
minLevel: LogLevel.info,
serviceName: 'my-app',
);
logger.info('User logged in', context: {
'userId': '12345',
'correlationId': 'abc-123',
});
}
Constructors
Properties
-
defaultContext
→ Map<
String, dynamic> -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- minLevel → LogLevel
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serviceName → String?
-
final
- version → String?
-
final
Methods
-
debug(
String message, {Map< String, dynamic> ? context}) → void - Logs a debug-level message.
-
error(
String message, {Map< String, dynamic> ? context, Object? error, StackTrace? stackTrace}) → void - Logs an error-level message.
-
info(
String message, {Map< String, dynamic> ? context}) → void - Logs an info-level message.
-
log(
LogLevel level, String message, {Map< String, dynamic> ? context, Object? error, StackTrace? stackTrace}) → void - Logs a message at the specified level.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
trace(
String message, {Map< String, dynamic> ? context}) → void - Logs a trace-level message.
-
warn(
String message, {Map< String, dynamic> ? context, Object? error}) → void - Logs a warning-level message.
-
withContext(
Map< String, dynamic> additionalContext) → JStructuredLogger - Creates a child logger with additional default context.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited