Skip to content

Commit 158e25c

Browse files
committed
Extend documentation on logback include files
Expand the Logback "How To" to provide further clarifications on the different include files available. See gh-16901
1 parent 1f97a60 commit 158e25c

File tree

1 file changed

+27
-4
lines changed
  • spring-boot-project/spring-boot-docs/src/main/asciidoc

1 file changed

+27
-4
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,31 +1269,54 @@ By default, Spring Boot picks up the native configuration from its default locat
12691269

12701270
[[howto-configure-logback-for-logging]]
12711271
=== 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:
12741290

12751291
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
12761292
----
12771293
<?xml version="1.0" encoding="UTF-8"?>
12781294
<configuration>
12791295
<include resource="org/springframework/boot/logging/logback/default.xml"/>
1296+
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
1297+
<root level="INFO">
1298+
<appender-ref ref="CONSOLE" />
1299+
</root>
12801300
<logger name="org.springframework.web" level="DEBUG"/>
12811301
</configuration>
12821302
----
12831303

1284-
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:
12851305

12861306
* `$\{PID}`: The current process ID.
12871307
* `$\{LOG_FILE}`: Whether `logging.file` was set in Boot's external configuration.
12881308
* `$\{LOG_PATH}`: Whether `logging.path` (representing a directory for log files to live in) was set in Boot's external configuration.
12891309
* `$\{LOG_EXCEPTION_CONVERSION_WORD}`: Whether `logging.exception-conversion-word` was set in Boot's external configuration.
12901310

12911311
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.
12931313

12941314
If Groovy is on the classpath, you should be able to configure Logback with `logback.groovy` as well.
12951315
If present, this setting is given preference.
12961316

1317+
NOTE: Spring extensions are not supported with Groovy configuration.
1318+
Any `logback-spring.groovy` files will not be detected.
1319+
12971320

12981321

12991322
[[howto-configure-logback-for-logging-fileonly]]

0 commit comments

Comments
 (0)