You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc
+27-4Lines changed: 27 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1269,31 +1269,54 @@ By default, Spring Boot picks up the native configuration from its default locat
1269
1269
1270
1270
[[howto-configure-logback-for-logging]]
1271
1271
=== Configure Logback for Logging
1272
-
If you put a `logback.xml` in the root of your classpath, it is picked up from there (or from `logback-spring.xml`, to take advantage of the templating features provided by Boot).
1273
-
Spring Boot provides a default level configuration that you can include if you want to set levels, as shown in the following example:
1272
+
If you need to apply customizations to logback beyond those that can be achieved with `application.properties`, you'll need to add a standard logback configuration file.
1273
+
You can add a `logback.xml` file to the root of your classpath for logback to find.
1274
+
You can also use `logback-spring.xml` if you want to use the <<spring-boot-features.adoc#boot-features-logback-extensions,Spring Boot Logback extensions>>)
1275
+
1276
+
TIP: The Logback documentation has a https://logback.qos.ch/manual/configuration.html[dedicated section that covers configuration] in some detail.
1277
+
1278
+
Spring Boot provides a number of logback configurations that be `included` from your own configuration.
1279
+
These includes are designed to allow certain common Spring Boot conventions to be re-applied.
1280
+
1281
+
The following files are provided under `org/springframework/boot/logging/logback/`:
1282
+
1283
+
* `defaults.xml` - Provides conversion rules, pattern properties and common logger configurations.
1284
+
* `console-appender.xml` - Adds a `ConsoleAppender` using the `CONSOLE_LOG_PATTERN`.
1285
+
* `file-appender.xml` - Adds a `RollingFileAppender` using the `FILE_LOG_PATTERN` with appropriate settings.
1286
+
1287
+
In addition, a legacy `base.xml` file is provided for compatibility with earlier versions of Spring Boot.
1288
+
1289
+
A typical custom `logback.xml` file would look something like this:
If you look at `base.xml` in the spring-boot jar, you can see that it uses some useful System properties that the `LoggingSystem` takes care of creating for you:
1304
+
Your logback configuration file can also make use of System properties that the `LoggingSystem` takes care of creating for you:
1285
1305
1286
1306
* `$\{PID}`: The current process ID.
1287
1307
* `$\{LOG_FILE}`: Whether `logging.file` was set in Boot's external configuration.
1288
1308
* `$\{LOG_PATH}`: Whether `logging.path` (representing a directory for log files to live in) was set in Boot's external configuration.
1289
1309
* `$\{LOG_EXCEPTION_CONVERSION_WORD}`: Whether `logging.exception-conversion-word` was set in Boot's external configuration.
1290
1310
1291
1311
Spring Boot also provides some nice ANSI color terminal output on a console (but not in a log file) by using a custom Logback converter.
1292
-
See the default `base.xml` configuration for details.
1312
+
See the `CONSOLE_LOG_PATTERN` in the `default.xml` configuration for an example.
1293
1313
1294
1314
If Groovy is on the classpath, you should be able to configure Logback with `logback.groovy` as well.
1295
1315
If present, this setting is given preference.
1296
1316
1317
+
NOTE: Spring extensions are not supported with Groovy configuration.
1318
+
Any `logback-spring.groovy` files will not be detected.
0 commit comments