Spring Boot: How to disable console logging using properties

To disable console logging, add the following properties to application.properties file:

# Empty this property to disable console logging
logging.pattern.console=

# Specify the path to the main log file so you will still have your logs somewhere
logging.file=/path/to/folder/application.log

If you want to enable console logging in your IDE, here are two ways to re-enable it:

  • Add an alias to the log file /path/to/folder/application.log in your Run Configuration
  • Override the property “logging.pattern.console” in your Run Configuration

Tested with Spring Boot 2.1.4

How to configure Log4j 2 with a properties file

You may want to migrate from Log4j 1.x to Log4j 2, for example because of performance improvements.

But, you don’t want to rewrite all your Log4j 1.x properties file, to use them for Log4j2, you have to slightly change them.

Here is an example of Log4j 2 configuration using properties. It defines two appenders: a console appender and a rolling file appender. (You can find a full working example in my Github repo)

# Declare loggers
name=LoggingConfig
appenders=a_console, a_rolling
rootLogger.level=info
rootLogger.appenderRefs=ar_console,ar_rolling
rootLogger.appenderRef.ar_console.ref=StdoutAppender
rootLogger.appenderRef.ar_rolling.ref=DailyRollingAppender

# Console logger
appender.a_console.type=Console
appender.a_console.name=StdoutAppender
appender.a_console.layout.type=PatternLayout
appender.a_console.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

# File logger
appender.a_rolling.type=RollingFile
appender.a_rolling.name=DailyRollingAppender
appender.a_rolling.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n

appender.a_rolling.fileName=log4j2-sample.log
appender.a_rolling.filePattern=log4j2-sample-%d{yyyy-MM-dd}.log

appender.a_rolling.layout.type=PatternLayout
appender.a_rolling.policies.type=Policies
appender.a_rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.a_rolling.policies.time.interval=1

Don’t hesitate to send me a message if you have any issue/question.