How to log the second argument in log4j

拥有回忆 提交于 2019-12-07 16:55:50

问题


I am trying to use log4j for the first time and I have configured it correctly, I just wanted to know how can I print the details of the argument passed as second parameter:

LogManager.getLogger(SomeName.class.getName()).info(message, detail);

and my configuration appender is:

<File name="file1" fileName="output.log">
    <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>

I think there should be some switch within the pattern after %msg if I want to log the detail there. But I am not sure what or how.


回答1:


Though I was expecting some better solution, but this seems to be the only one available.

LogManager.getLogger(SomeName.class.getName()).info("Message: {}, Detail: {}", message, detail);



回答2:


LogManager.getLogger().info(
    "The {} is that {}, there are more {},"
 + " not necessarily in a message + details {}.",
    "reason", "often", "parameters", "relationship");


来源:https://stackoverflow.com/questions/37755046/how-to-log-the-second-argument-in-log4j

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