Log4j: Log only message string without logging className and other details

喜欢而已 提交于 2021-02-08 10:22:09

问题


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 ?

Example:

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

Desired Log statement

Hi This is a log message

回答1:


You have to change config file log4j.xml

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"/>


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"/>


来源:https://stackoverflow.com/questions/53738244/log4j-log-only-message-string-without-logging-classname-and-other-details

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