Logging levels
SpringApplication applies the logging.level.* and logging.group.* properties to the SpringLog facade on every start, with or without spring_boot_starter_logging. It is Spring Boot's LoggingApplicationListener. The starter adds the outputs (console patterns, files, a buffer); the levels belong to spring_boot_dart.
Why
Log levels change more often than code: more detail for one package while debugging, less noise in production. Setting them as properties means a command-line option, an environment variable or a profile file changes them, like any other setting.
Example
# lib/resources/application.yml
logging:
level:
root: info
neon.checkout: debug # and every neon.checkout.* logger
payments: trace # a group, below
group:
payments: [neon.card, neon.cash]
# lib/resources/application.properties: the same
logging.level.root=info
logging.level.neon.checkout=debug
logging.group.payments=neon.card,neon.cash
logging.level.payments=trace
LOGGING_LEVEL_NEON_CHECKOUT=debug dart run bin/main.dart
dart run bin/main.dart --logging.level.root=warn
// @Log(topic: 'neon.checkout') gives the class a logger of that name.
@Service()
@Log(topic: 'neon.checkout')
class Checkout {
void pay() => log.debug(() => 'paying'); // shown with neon.checkout at debug
}
The rules
| Key | Meaning |
|---|---|
logging.level.root (or a plain logging.level) |
The level of every logger without one of its own. root is matched in any case |
logging.level.<logger> |
The level of a logger and of every logger below it (neon.checkout.cart) |
logging.group.<group> |
A list of logger names; logging.level.<group> then sets each of them |
- The levels are
trace,debug,info,warn(orwarning),error(orfatal) andoff.false, what YAML makes of an unquotedoff, meansoff. - A value that is no level stops the start:
logging.level.neon: failed to convert to LogLevel (was "loud"; use trace, debug, info, warn, error, fatal or off). - An empty value leaves the level inherited.
- The levels are set once the config files are read, before the banner and the beans. Log lines written earlier in the start are held and released at those levels.
- Without
spring_boot_starter_logging,SpringLogwrites records of INFO and above to the console (Spring's default level); the starter adds patterns, files and the buffer.
Predefined groups
Like Spring Boot's web and sql groups:
| Group | Loggers |
|---|---|
web |
spring.web, spring.websocket |
sql |
spring.jdbc.core.JdbcTemplate, spring.jdbc.core.StatementCreatorUtils |
# Every request of the web starters, and every SQL statement.
logging.level.web=debug
logging.level.sql=debug
A logging.group.web of the application replaces the predefined list.
--debug and --trace
| Switch | Effect |
|---|---|
--debug (or debug=true, DEBUG=true) |
Sets spring_core_dart, spring_boot_dart and spring.web.server to debug, and logs the condition evaluation report |
--trace (or trace=true) |
Sets the same loggers to trace; wins over --debug |
Any value but false turns them on, so --debug alone works. Levels in logging.level.* win over them.
In code
SpringApplication.applyLoggingLevels(environment) does the same for an environment prepared without SpringApplication. It clears the levels an earlier call set.
In Spring (Java)
The same keys, groups and switches. Logger names are Dart library names or the names given to SpringLog, not Java packages, so logging.level.org.springframework=debug has no effect; use --debug or the names above.