多个log4j实例配置
我想使用 log4j Logger 的多个实例。我需要将不同的 Properties 对象附加到每个 log4j Logger 实例。
以下是为一个实例配置的代码:
LOG4J = org.apache.log4j.Logger.getLogger(Logger.class);
Properties log4jProps = new Properties();
...
PropertyConfigurator.configure(log4jProps);
如果我想要两个 log4j 实例并且每个实例都有不同的属性怎么办?
I want to use multiple instances of the log4j Logger. I need to attach different Properties objects to each of these log4j Logger instances.
Here is the code to configure for one instance:
LOG4J = org.apache.log4j.Logger.getLogger(Logger.class);
Properties log4jProps = new Properties();
...
PropertyConfigurator.configure(log4jProps);
What if I want to have two log4j instance and each of them has different properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能更详细地解释一下为什么需要多个记录器吗?我认为不可能有多个 log4j 实例。
如果您只想要多个附加程序,请查看此处:
这是上面链接中的 log4j.properties:
这些行:
说出以下内容:
也可以提供完整的类名:
表示记录从 com.lewscanon.SomeClass 类到附加程序 F、级别 warn 及以上的所有内容。
我想上面的内容已经足够细化了,但是如果您绝对需要更细化(但我认为这不够实用),请按照:
Logger.getLogger(String name)
接受名称。因此,您可以执行以下操作:并使用 Logger.getLogger("myFancyLogger") 获取使用级别信息记录到附加程序 F 的记录器。
Can you explain why you want multiple loggers in more detail? I don't think it's possible to have multiple log4j instances.
If you just want multiple appenders, look here:
Here's the log4j.properties from the above link:
These lines:
say the following:
It's also possible to supply full class names:
means log everything from
com.lewscanon.SomeClass
class to appender F, level warn and above.I suppose the above is granular enough, but if you absolutely need it more granular (I don't think that's practical enough, though), per:
Logger.getLogger(String name)
accepts names. So you can do something like:and use
Logger.getLogger("myFancyLogger")
to get the logger that logs to appender F with level info.