Logback:如何从日志文件中删除类名称和日志级别? [英] Logback: How to remove class names and log level from Log file?

查看:102
本文介绍了Logback:如何从日志文件中删除类名称和日志级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring boot应用程序中使用Logback.

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

即从日志语句中删除"[pool-2-thread-1] INFO".

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

推荐答案

如果您使用的是Spring Boot默认控制台和文件日志,即您的类路径中没有任何logback.xml,则可以使用logging.pattern.consolelogging.pattern.file属性.例如,将其添加到您的application.yml文件中将为您解决问题:

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'

否则,将此模式添加到logback.xml中的相应文件追加器中:

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

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

这篇关于Logback:如何从日志文件中删除类名称和日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆