Skip to content

Commit 91c801d

Browse files
committed
Add how-to log to file without console section
Fixes gh-4388
1 parent 40abd13 commit 91c801d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ using the "logging.config" property.
12511251
=== Configure Logback for logging
12521252
If you put a `logback.xml` in the root of your classpath it will be picked up from
12531253
there
1254-
(or `logback-spring.xml` to take advantage of the templating features provided by Boot). Spring Boot provides a default base configuration that you can include if you just
1254+
(or `logback-spring.xml` to take advantage of the templating features provided by Boot).
1255+
Spring Boot provides a default base configuration that you can include if you just
12551256
want to set levels, e.g.
12561257

12571258
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
@@ -1283,6 +1284,33 @@ If Groovy is on the classpath you should be able to configure Logback with
12831284

12841285

12851286

1287+
[[howto-configure-logback-for-logging-fileonly]]
1288+
==== Configure logback for file only output
1289+
If you want to disable console logging and write output only to a file you need a custom
1290+
`spring-logback.xml` that imports `file-appender.xml` but not `console-appender.xml`:
1291+
1292+
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
1293+
----
1294+
<?xml version="1.0" encoding="UTF-8"?>
1295+
<configuration>
1296+
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
1297+
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
1298+
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
1299+
<root level="INFO">
1300+
<appender-ref ref="FILE" />
1301+
</root>
1302+
</configuration>
1303+
----
1304+
1305+
You also need to add `logging.file` to your `application.properties`:
1306+
1307+
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
1308+
----
1309+
logging.file=myapplication.log
1310+
----
1311+
1312+
1313+
12861314
[[howto-configure-log4j-for-logging]]
12871315
=== Configure Log4j for logging
12881316
Spring Boot also supports either http://logging.apache.org/log4j/1.2[Log4j] or

0 commit comments

Comments
 (0)