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
Properties
Methods
-
debug(
Object? message, {Map< String, Object?> fields = const {}}) → void -
Logs
messageat SpringLogLevel.debug; see log. -
error(
Object? message, {Object? error, StackTrace? stackTrace, Map< String, Object?> fields = const {}}) → void -
Logs
messageat SpringLogLevel.error, with theerrorthat caused it when there is one; see log. -
info(
Object? message, {Map< String, Object?> fields = const {}}) → void -
Logs
messageat 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. Alwaystruewhile a hold is active (except for SpringLogLevel.off). -
log(
SpringLogLevel level, Object? message, {Object? error, StackTrace? stackTrace, Map< String, Object?> fields = const {}}) → void -
Logs
messageatlevelwhen the level is enabled, with an optionalerror, itsstackTraceand structuredfields. -
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
messageat SpringLogLevel.trace; see log. -
warning(
Object? message, {Object? error, StackTrace? stackTrace, Map< String, Object?> fields = const {}}) → void -
Logs
messageat SpringLogLevel.warning, with theerrorthat 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.rootsets 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
nameand of the loggers below it (a.balso applies toa.b.c);nullmakes it inherit again. Configuration does the same withlogging.level.<name>. -
withFields<
R> (Map< String, Object?> fields, R body()) → R -
Runs
bodywithfieldsadded to every record logged inside it, including asynchronous work it starts, and returns its result.