log4j 将日志记录限制为仅一个 jar
我有一个项目,该项目又被其他几个项目使用。我希望 log4j
仅将我的日志记录到我在属性文件中指定的文件中。其他项目使用自己的日志记录机制,我无法控制它们。我的 log4j 文件不应影响其他项目的日志记录。我应该如何配置我的 log4j 属性文件?
到目前为止,我正在做的是设置 log4j.rootLogger = ERROR
和我的模块 log4j.logger.com.xyz.myproject = INFO, FILE
。这会在不影响其他项目记录器的情况下工作吗?或者可能将日志记录限制为仅我的罐子?
谢谢
I have a project which is in turn used by several other projects. I want log4j
to log only my logs to a file that I have specified in the properties file. Other project use their own logging mechanisms and I have no control over them. My log4j files should not affect other project's logging. How should i configure my log4j property file?
So far what I'm doing is setting log4j.rootLogger = ERROR
and for my module log4j.logger.com.xyz.myproject = INFO, FILE
. Will this work without affecting other project's loggers? Or possibly limit logging to only my jar?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于其他项目的包结构。假设
com.abc.def.ghi
那么更改
com.abc.def
日志记录级别会影响其他项目 - 他们将开始在com.def.ghi 定义的级别上记录日志。 abc.def
。验证情况并非如此,您应该是安全的。
It depends on the package structure of the other projects. Supposing that
Logger.getLogger(ClassA.class)
ANDlog4j.category.loggerName
settings ANDcom.abc.def
and other projects have packages deeper in the hierarchycom.abc.def.ghi
THENchanging
com.abc.def
logging level would affect other projects - they'll start logging on the level defined bycom.abc.def
.Verify that it's not the case and you should be safe.
我想你的 jar 完全包含在你自己的包中(例如 com.foo.mypackage)。在这种情况下,只需添加到您的 log4j 配置中即可:
问候,
M。
I suppose your jar is entirely contained in your own package (ex com.foo.mypackage). In this case, is just enough to add to your log4j configuration something like:
Regards,
M.