java 如何在 log4j 中记录第二个参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37755046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to log the second argument in log4j
提问by Hassan
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:
我第一次尝试使用 log4j 并且我已经正确配置了它,我只是想知道如何打印作为第二个参数传递的参数的详细信息:
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.
%msg
如果我想在那里记录细节,我认为应该在模式中进行一些切换。但我不确定是什么或如何。
回答by Hassan
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);
回答by Remko Popma
LogManager.getLogger().info(
"The {} is that {}, there are more {},"
+ " not necessarily in a message + details {}.",
"reason", "often", "parameters", "relationship");