EvilJinious1
EvilJinious1

Reputation: 2863

adding a custom logback log pattern in spring boot yml file

I have been looking all over and was not able to figure this out. I need to add a custom log pattern for log output. I can do this very easily through a logback.xml file in the resources directory and it works exactly as I want it.

However, I would like to be able to do this throughout he application.yml file if that is possible. Mostly because I would like to externalize it in one place.

I have the normal logging stuff in application.yml as below:

    #logging definitions

use the hierarchy tree to set logging levels

logging: file: logs/accountservice.log level: org: springframework: 'INFO' com: mangofactory: swagger: scanners: 'OFF' cisco: services: 'DEBUG'

The log pattern is like this:

Upvotes: 2

Views: 7203

Answers (2)

Ali Dehghani
Ali Dehghani

Reputation: 48183

You can use logging.pattern.console and logging.pattern.file for customizing the log pattern to use on the console and file, respectively. For example, if you add this to your application.yml:

logging:
  pattern:
    console: '%d{HH:mm:ss.SSS} %msg%n'

Your console logs would be like:

16:09:43.299 Log message

Checkout the Spring Boot documentation on Customizing log configuration for more information.

Upvotes: 4

Phil Webb
Phil Webb

Reputation: 8642

As of Spring Boot 1.2 it's not possible to customize the pattern using application.yml. There is a feature request open to improve this (https://github.com/spring-projects/spring-boot/issues/1788).

Upvotes: 4

Related Questions