问题
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