java123999
java123999

Reputation: 7394

Logback: How to remove class names and log level from Log file?

I am using Logback in my Spring boot application.

In my log file I currently get the sample output:

16:09:43.299 [pool-2-thread-1] INFO  c.b.r.h.k.s.myClassName - Log message

How can I change my log settings so that it only looks like the following:

16:09:43.299 Log message

I.e removing the "[pool-2-thread-1] INFO" from the log statement.

Upvotes: 1

Views: 2262

Answers (1)

Ali Dehghani
Ali Dehghani

Reputation: 48123

If you're using Spring Boot default console and file logs, i.e. haven't any logback.xml in your classpath, you can use logging.pattern.console and logging.pattern.file properties. For example, adding this to your application.yml file will do the trick for you:

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

Otherwise, add this pattern to your corresponding file appender in your logback.xml:

<pattern>%d{HH:mm:ss.SSS} %msg%n</pattern>

Upvotes: 5

Related Questions