
# spring_boot_starter_logging

`spring_boot_starter_logging` is the logging backend of Spring for Dart, the Dart counterpart of `spring-boot-starter-logging`. Add it, and the lines of `SpringLog` come out in Spring Boot's format, configured by the same `logging.*` properties a Spring Boot application uses, with Logback's pattern syntax.

No code is needed: the generator finds the starter, and a `LoggingSystem` is installed behind `SpringLog` when the application starts. The other starters (web, Feign, WebSocket, scheduling, cache) bring it along.

## Why

`SpringLog`, the logger of `spring_core_dart`, alone prints plain lines to the console. An application usually wants more:

- Spring Boot's line format, with time, level, process id, application name and logger, coloured on a terminal;
- its own format, written as a Logback pattern;
- a log file on a server, rolled over by size;
- a log screen or a "send logs" button in a mobile app, which has no terminal its users can read;
- levels changed in properties, by environment variables, or while the application runs.

The starter gives all of this, with Spring Boot's property names, so a Spring Boot configuration works as it is.

## Setup

```yaml
# pubspec.yaml
dependencies:
  spring_boot_starter_logging: ^0.9.0
```

Run `dart run build_runner build` again after adding it, so the generated `springApplication` lists its auto-configuration.

## Example

```dart
// lib/checkout.dart
import 'package:spring_boot_dart/spring_boot_dart.dart';

import 'spring_gen/app.spring.dart'; // the generated file of the scan holds the log getter

@Service()
@Log(topic: 'neon.checkout') // the logger's name; without topic: <package>.<Class>
class Checkout {
  // The order goes along as a field: searchable, and printed after the message.
  void pay(int order, double amount) =>
      log.info('paid $amount', fields: {'order': order});
}
```

```yaml
# lib/resources/application.yml
spring:
  application:
    name: shop
logging:
  level:
    root: info
    neon.checkout: debug
  file:
    name: logs/shop.log
```

The console line, in Spring Boot's format:

```text
2026-10-23T21:08:01.580Z  INFO 4711 --- [shop] [           main] neon.checkout                            : paid 12.5 {order=1}
```

The same line goes to `logs/shop.log`, without colours. Where no generated file is at hand (a library, a script, a top-level function), create the logger yourself: `const log = SpringLog('neon.checkout');`.

## What starts

The auto-configuration (`springBootStarterLoggingAutoConfiguration`) adds three beans, unless `logging.enabled=false`:

| Bean | What it is |
|---|---|
| `loggingSystemInitializer` | Configures `LoggingSystem.instance` from the `logging.*` properties and installs it before any application bean is created; uninstalls it when the context closes |
| `loggingSystem` | `LoggingSystem.instance`, to change levels at run time or add appenders |
| `logBuffer` | The in-memory `LogBuffer`, for a log screen |

The levels (`logging.level.*`, `logging.group.*`) are applied by `spring_boot_dart` itself, with or without this starter; the starter adds the outputs. See [Logging levels](../spring-boot-dart/logging-levels.md).

Lines logged during the start, before the system is set up, are replayed into the file, the buffer and added appenders, as Spring Boot's `DeferredLogs` does. A failed start keeps the system installed until the failure report is logged, so the report reaches the file too.

## What is inside

- [The console](console.md): the default format, colours, the target, thresholds.
- [Patterns](patterns.md): every conversion word of `logging.pattern.console` and `logging.pattern.file`.
- [Log files](log-files.md): `logging.file.*`, rolling over, write failures, Flutter's file directory.
- [Log screen](log-buffer.md): `LogBuffer`, queries, live lists, export.
- [Levels at run time and appenders](appenders.md): `LoggingSystem.setLogLevel`, your own `LogAppender`, use without Spring Boot.
- [All properties](properties.md): every key of the starter.
- [Differences from Spring](differences.md): what works differently than with Logback.

## In Spring (Java)

```java
@Slf4j(topic = "neon.checkout")   // Lombok
@Service
class Checkout {
  void pay(int order, double amount) {
    log.info("paid {}", amount);
  }
}
```

```properties
logging.level.neon.checkout=debug
logging.file.name=logs/shop.log
logging.logback.rollingpolicy.max-file-size=10MB
```

Differences that matter:

- There is no Logback and no `logback-spring.xml`: everything is set with properties, and appenders are added in code.
- The rolling policy keys are `logging.file.rolling-policy.*`; the `logging.logback.rollingpolicy.*` names stop the start.
- The console is coloured by default (`always`; Spring Boot's default is `detect`).
- Log times are UTC: Dart has no time zone database.
- The full list is on [Differences from Spring](differences.md).

## See also

- [spring_boot_dart](../spring-boot-dart/index.md)
- [Logging levels](../spring-boot-dart/logging-levels.md)
- [Logging in spring_core_dart](../spring-core-dart/logging/index.md)
- [SpringLog](../spring-core-dart/logging/spring-log.md)
- [What a build contains](optimizations.md)
