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

柔情痞子 提交于 2019-12-24 17:07:28

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/36627390/logback-how-to-remove-class-names-and-log-level-from-log-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!