
# Logging

Every package of the family, and the applications built on it, log through one facade: `SpringLog`.

## Why use it

A library should not decide where log lines go; the application should. With one facade, the framework, the starters and your own code all write records the same way, and one place decides what is shown and where it goes. Levels can be set per logger name, so you can turn on debug output for one part of the application.

Without a logging backend, records of level `info` and above are written to the console as `[logger] LEVEL: message`. A backend such as `spring_boot_starter_logging` replaces the handler. With Spring Boot, levels come from `logging.level.*` properties.

Do not use `print` for application logs: it has no levels, no logger names and cannot be redirected.

## Example

```dart
import 'package:spring_core_dart/spring_core_dart.dart';
import 'package:my_app/spring_gen/src/beans.spring.dart'; // the generated file

@Service()
@Log() // a `log` getter: the logger `my_app.Checkout`
class Checkout {
  void pay(String orderId) {
    log.info('order placed', fields: {'order': orderId});
    // A closure is only called when debug is enabled.
    log.debug(() => 'paying $orderId');
  }
}
```

## Pages

- [SpringLog](spring-log.md): loggers, levels, `@Log`, structured fields, handlers and the console format.

## See also

- [Beans](../beans/index.md)
- [Configuration](../config/index.md)
