Maven 插件记录器兼容性
我正在编写一个 Maven 插件 (Mojo),它导入其他项目使用的 Jar 库。该库中至少有一个类使用 Apache Log4j 进行日志记录,但 Maven 向 Mojo 提供的记录器不会正确配置 Log4j。
有什么简单的方法可以在这些之间建立桥梁吗?不幸的是, org.apache.log4j.Logger 和 org.apache.maven.logging.Log 不共享通用的超接口或超类,所以我不能简单地拥有一个setLog()
类型函数。欢迎任何建议;目前我计划要么忽略它,要么编写一个可以使用其中任何一个的桥类。
I am writing a Maven plugin (Mojo) that imports a Jar library used by other projects. At least one of the classes in that library use Apache Log4j for logging, but Log4j is not going to be properly configured by the logger that Maven provides to the Mojo.
Is there any simple way to bridge between these? Unfortunately, org.apache.log4j.Logger
and org.apache.maven.logging.Log
do not share a common superinterface or superclass, so I can't simply have a setLog()
type function. Any suggestions would be welcome; currently I am planning to either just ignore it, or write a bridge class that can use either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,并解决了在 Maven Logger 和 Log4j 之间编写一个简单的桥:
在我的 Mojo 中,我使用了 Log4j API 的 BasicConfigurator 类,以及该桥的一个实例:
我不知道如果 Maven 基础设施已经有这个桥,我还没有尝试搜索更“类似 Maven”的东西,但这个解决方案工作得很好。
I had the same problem and solved writing a simple bridge across Maven Logger and Log4j:
And in my Mojo, I used the BasicConfigurator class of Log4j API, with an instance of this bridge:
I don't know if Maven infrastructure already have this bridge, I haven't tried to search something more "maven-like", but this solution worked fine.
如果您想编写桥接类,请查看 SLF4J 源代码: http://www .slf4j.org/legacy.html#log4j-over-slf4j
他们在 log4j 桥中做了一些非常相似的事情。
If you want to write a bridge class, look at SLF4J sources: http://www.slf4j.org/legacy.html#log4j-over-slf4j
They are doing something quite similar in their log4j bridge.