LoggingSystem class final

Where log records go once this starter is installed: it receives every record written through SpringLog and sends it to the console, the in-memory buffer, the log file and any appender you added.

SpringLog alone only prints plain lines. This class gives an application Spring Boot's logging: formatted, coloured console lines, a log file that rolls over, a buffer for an in-app log screen, and logger levels that can change while the application runs. There is one per process, instance. With Spring Boot, the starter configures it from the logging.* properties and installs it as the context starts, so most applications only write properties. Code uses it to change a level at runtime, to add an output with addAppender, or, in Flutter, to send the console to debugPrint and set fileDirectory before the application starts. Without Spring Boot, call configure and install yourself.

// An admin action turns on debug lines for the checkout, no restart.
@Service()
class LogLevels {
  LogLevels(this.logging); // the starter's `loggingSystem` bean

  final LoggingSystem logging;

  void debugCheckout() =>
      logging.setLogLevel('neon.checkout', SpringLogLevel.debug);
}

Spring Boot (Java):

LoggingSystem logging = LoggingSystem.get(classLoader);
logging.setLogLevel("neon.checkout", LogLevel.DEBUG);

The properties it reads (lib/resources/application.properties); the logging.level.* and logging.group.* ones are applied by spring_boot_dart itself:

logging.level.root=info                 # handled by spring_boot_dart
logging.level.neon.checkout=debug
logging.pattern.console=%d{HH:mm:ss} %-5p [%logger] %m%X%n%ex
logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS
logging.pattern.level=%5p
logging.include-application-name=true   # [spring.application.name] in lines
logging.threshold.console=warn          # console: warnings only
spring.output.ansi.enabled=always       # colours: always (default)/detect/never
logging.console.enabled=true
logging.buffer.enabled=true
logging.buffer.capacity=2000
logging.threshold.buffer=debug
logging.file.name=logs/shop.log         # or logging.file.path=logs (spring.log)
logging.pattern.file=%d %5p [%logger] %m%X%n%ex
logging.threshold.file=info
logging.file.rolling-policy.max-file-size=10MB   # shop.log.1, .2, ...
logging.file.rolling-policy.max-history=7        # rolled-over files kept
logging.file.rolling-policy.total-size-cap=0B    # total (0B: no limit)
logging.file.rolling-policy.clean-history-on-start=false
logging.enabled=false                   # leave SpringLog alone

Relative file locations are resolved against fileDirectory when it is set (for example the app's documents directory in Flutter), else against the working directory. Files are not written on the web.

Properties

appenders → List<LogAppender>
The outputs that receive records now, in the order they get them: console and buffer when enabled, file when there is one, then the ones added with addAppender. An unmodifiable snapshot.
no setter
buffer → LogBuffer
The last records in memory, for an in-app log screen; also the logBuffer bean. It keeps logging.buffer.capacity records, 1000 by default.
final
bufferEnabled ↔ bool
Whether buffer receives records (logging.buffer.enabled, true by default).
getter/setter pair
console → ConsoleAppender
The console output. The starter sets its pattern, colours and threshold from logging.pattern.console, spring.output.ansi.enabled and logging.threshold.console; its lines go to standard output on the Dart VM (logging.console.target=stderr for standard error) and to print in Flutter and on the web, unless you change console.out.
final
consoleEnabled ↔ bool
Whether console receives records. The starter sets it from logging.console.enabled, and to false when logging.pattern.console is empty.
getter/setter pair
file → FileAppender?
The log file set up from logging.file.*; null when no file is configured, on the web, when logging.pattern.file is empty, or when the file cannot be opened.
no setter
fileDirectory ↔ String?
The directory a relative logging.file.name or logging.file.path is resolved against; null uses the working directory.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
isInstalled → bool
Whether this system is the SpringLog.handler now, so records come here.
no setter
loggerLevels → Map<String, SpringLogLevel>
The levels set for single loggers, by logger name, from logging.level.* and setLogLevel; the root level is not in it.
no setter
rootLevel ↔ SpringLogLevel
The level of every logger that has none of its own nor an ancestor with one (logging.level.root); setting it takes effect at once.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAppender(LogAppender appender) → void
Sends every record from now on to appender as well, after the built-in outputs. It stays until removeAppender, also across uninstall and a new start.
configure(PropertyResolver environment) → void
Sets up the outputs from the logging.* properties of environment, the ones listed on this class. It does not install the system.
install() → void
Makes this system receive every SpringLog record by becoming the SpringLog.handler; the handler it replaces is kept for uninstall. Does nothing when already installed.
levelOf(String logger) → SpringLogLevel
The level that applies to logger: its own, else that of its nearest ancestor with one, else the root level. ROOT (in any case) gives the root level.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAppender(LogAppender appender) → bool
Stops sending records to appender, an appender added with addAppender, and closes it. Returns false, and does nothing, when it was not added. An error closing it is logged, not thrown.
setLogLevel(String? loggerName, SpringLogLevel? level) → void
Changes the level of loggerName and its descendants while the application runs, as logging.level.<name> does at startup.
toString() → String
A string representation of this object.
override
uninstall() → void
Gives SpringLog back the handler it had before install, and closes the log file. The starter calls it when the context closes. When some other code has replaced the handler in between, that handler stays.

Operators

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

Static Properties

instance → LoggingSystem
The logging system of this process. There is only one because SpringLog is global; the starter's loggingSystem bean is this object.
final

Constants

rootLoggerName → const String
The name that means the root logger in setLogLevel and levelOf, matched in any case, as Spring Boot's LoggingSystem.ROOT_LOGGER_NAME.