SpringLog class final

A named logger: the object code logs through, and the static switches (levels, handler, holds) of logging as a whole.

It is the one logging API of the whole family: the framework, the starters and applications log through it, and a logging backend (such as spring_boot_starter_logging) decides where records go by setting handler. Without a backend, records of SpringLogLevel.info and above are written to the console (Spring's default level either way). An application gets a logger from @Log() or declares one as a constant; it sets levels in configuration (logging.level.<name>) or with setLevel.

// A logger shared by the checkout code.
const log = SpringLog('neon.checkout');

log.info('order placed');
log.debug(() => 'basket: ${basket.dump()}'); // built only if enabled
log.error('payment failed', error: e, stackTrace: s, fields: {'order': 42});

SpringLog.level = SpringLogLevel.info;                   // root level
SpringLog.setLevel('neon.checkout', SpringLogLevel.debug); // and below

Levels follow the dots in names: neon.checkout.payment uses the level set for neon.checkout.payment, else neon.checkout, else neon, else the root level.

Spring (Java):

private static final Log log = LogFactory.getLog(Checkout.class);
log.info("order placed");

Constructors

SpringLog(String name)
Creates a logger named name; a const logger costs nothing until it logs.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The logger name, such as spring_core_dart.context, used to look up its level.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

debug(Object? message, {Map<String, Object?> fields = const {}}) → void
Logs message at SpringLogLevel.debug; see log.
error(Object? message, {Object? error, StackTrace? stackTrace, Map<String, Object?> fields = const {}}) → void
Logs message at SpringLogLevel.error, with the error that caused it when there is one; see log.
info(Object? message, {Map<String, Object?> fields = const {}}) → void
Logs message at SpringLogLevel.info; see log.
isEnabled(SpringLogLevel level) → bool
Whether this logger currently emits records of level. Check it before building an expensive message, or pass a closure as the message instead. Always true while a hold is active (except for SpringLogLevel.off).
log(SpringLogLevel level, Object? message, {Object? error, StackTrace? stackTrace, Map<String, Object?> fields = const {}}) → void
Logs message at level when the level is enabled, with an optional error, its stackTrace and structured fields.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override
trace(Object? message, {Map<String, Object?> fields = const {}}) → void
Logs message at SpringLogLevel.trace; see log.
warning(Object? message, {Object? error, StackTrace? stackTrace, Map<String, Object?> fields = const {}}) → void
Logs message at SpringLogLevel.warning, with the error that caused it when there is one; see log.

Operators

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

Static Properties

configuredLevels → Map<String, SpringLogLevel>
The levels set with setLevel, by logger name, as a read-only copy.
no setter
currentFields → Map<String, Object?>
The fields withFields has set for the code running now; empty outside any withFields.
no setter
handler ↔ SpringLogHandler
Where records go: the function that receives every record that passes its logger's level. printLogHandler unless replaced; a logging backend replaces it.
getter/setter pair
level ↔ SpringLogLevel
The root level: the minimum level of loggers without a level of their own (setLevel); SpringLogLevel.info unless set, as in Spring with or without Spring Boot's logging. The property logging.level.root sets it in an application.
getter/setter pair

Static Methods

hold() → SpringLogHold
Holds back every record from now on, of any level, until SpringLogHold.release emits those that pass the levels of that time.
levelOf(String name) → SpringLogLevel
The level that applies to the logger name: its own, or the nearest one set above it, or the root level.
listen(SpringLogHandler listener) → void Function()
Also sends every emitted record to listener, after handler, for example to capture logs in a test or show them in an app. Call the returned function to stop. Errors thrown by listeners are ignored.
resetLevels() → void
Removes every level set with setLevel; the root level stays. Useful between tests.
setLevel(String name, SpringLogLevel? level) → void
Sets the minimum level of the logger name and of the loggers below it (a.b also applies to a.b.c); null makes it inherit again. Configuration does the same with logging.level.<name>.
withFields<R>(Map<String, Object?> fields, R body()) → R
Runs body with fields added to every record logged inside it, including asynchronous work it starts, and returns its result.