如何在log4j中记录第二个参数 [英] How to log the second argument in log4j

查看:432
本文介绍了如何在log4j中记录第二个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试首次使用log4j,并且已正确配置它,我只是想知道如何打印作为第二个参数传递的参数的详细信息:

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);

我的配置附加器是:

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

如果要在此记录详细信息,我认为在%msg之后的模式中应该有一些切换.但是我不确定是什么或如何.

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.

推荐答案

虽然我期望有更好的解决方案,但这似乎是唯一可用的解决方案.

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);

这篇关于如何在log4j中记录第二个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆