I am building a command line application using Spring Boot. In such an application, logback console logging is not appropriate. How can I completely disable the console appender, but still have the file appender working with the default Spring Boot support?
Update
I have created a feature request for simpler support of this feature here:
Just add a file called
logback.xml
insrc/main/resources
with content like (copied verbatim except for console part from Spring Boot's source):Note that
is needed in order to support setting the log file from Spring Boot's
logging.file
andlogging.path
.If all you want to do is set some standard log file, you could set place it's path in property above.
Update (02-04-2015)
In newer versions of Spring Boot you can easily just include the
base.xml
from Spring Boot and create the followinglogback.xml
.Update (15-09-2017)
In order to get this working on Spring Boot 1.5.x and 2.0.0.M4 I added a file called
logback-spring.xml
and added it in theresources
directory. The file could look like thisAdd the below to your application.properties
Include
file-appender.xml
and notconsole-appender
with the following configuration inlogback-spring.xml
:You also need to add
logging.file
to yourapplication.properties
This is in compliance with what is mentioned on spring boot documentation - http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
Tested with latest 1.3.1 spring boot release..
place logback.xml under resource folder
logback.xml
Also make sure to remove exclusions of spring-boot-starter-logging from "spring-boot-starter" and "spring-boot-starter-web" dependency, if you added exclusions before.
No need of below dependencies
application.properties
I tried removing console configuration from logback.xml. But, It was still logging in console. So What I did is, I just removed the appender being added in the logging configuration by springboot. Thereby, we can stop springboot logging in console and separate log file. Add the below lines at the end of your application specific appenders are added. Your custom appender should not match any of these appender names. It worked for me.
Using Spring Boot 1.3.0, I created a file
logback-spring.xml
(insrc/main/resources
with the following content:Additionally, I added the
logging.file
property inapplication-staging.properties
andapplication-prod.properties
to specify what the file name should be.This will log to console for
dev
and to file forstaging
orprod
profiles.