Log4j:仅记录消息字符串,而不记录className和其他详细信息 [英] Log4j: Log only message string without logging className and other details

查看:37
本文介绍了Log4j:仅记录消息字符串,而不记录className和其他详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,正在使用log4j2.我只想记录日志消息,而不记录诸如className,日志级别,时间戳等内容.我确实看到了有关自定义追加程序等的一些建议.但是,是否仅通过修改默认配置就没有一种更简单的方法来实现这一目标?

I have a java application and I am using log4j2. I want to only log the log message without logging things like className, log level, timestamp etc. I do see some suggestions regarding custom appender etc. But isn't there a simpler way to achieve this by just modifying the default configuration ?

示例:

log.info(" Hi This is a log message");

所需的日志语句

Hi This is a log message

推荐答案

您必须更改配置文件 log4j.xml

该文件中需要更改的元素是 pattern :
如果您使用的是 log4j.properties ,则更改相应的元素.
模式元素的示例:

The element need to be change in that file is pattern :
if you are using log4j.properties then change corresponding element.
example of pattern element:

<PatternLayout pattern="%d [%p] %c %m%n"/>


此处 d 日期的ID
p 是优先级
c 用于类名
m 是邮件
n 是分隔符
如果您不想要任何东西,请从 pattern 条目中删除.

根据您的要求进行了修改


here d id for date
p is for priority
c is for Class Name
m is fro message
n is fro separator
if you dont want any thing then remove from pattern entry.

Modified as per your requirement

<PatternLayout pattern=" %m%n"/>

这篇关于Log4j:仅记录消息字符串,而不记录className和其他详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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