Log4j:仅记录消息字符串,而不记录className和其他详细信息 [英] Log4j: Log only message string without logging className and other details
问题描述
我有一个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 是分隔符
如果您不想要任何东西,请从
根据您的要求进行了修改
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屋!