log4j 额外的日志记录参数
我正在开发一个(内部)库,我想强制使用该库的开发人员在记录错误或致命级别消息时包含文本 ID。 在不修改 log4j 的情况下,我们想要强制执行的内容类似于:
logger.error( "E1234:An error has goneed" );
在没有对 log4j 进行扩展或进行少量扩展的情况下,我们可以在夜间构建期间扫描源代码来验证是否包含文本 ID,或实现一个在运行时验证它的 log4j 附加程序。
然而,我们想要的是向错误方法添加一个额外的参数。 例如:
logger.error( "E1234", "发生错误" );
这可以通过为 log4j Logger 类实现一些外观类来处理。
还有其他人有类似的问题吗? 你的解决方案是什么? 现在,我们更喜欢第一个代码示例。 将来我们可能会实现代码分析器在夜间构建期间执行(或者有人知道一些现有的代码分析器可以配置为检测 error() 方法调用中丢失的文本 ID 吗?)
I'm developing a (internal) library where I want to enforce that developers using this lihrary include a text ID when logging error or fatal level messages. Without modifying log4j, what we want to enforce is similar to:
logger.error( "E1234:An error has occured" );
With none or minor extension to log4j we could either, during nightly builds, scan the source code to verify that the text ID is included, or implement a log4j appender that verifies it during runtime.
What we would like, however, is to add an extra argument to the error-method. E.g.:
logger.error( "E1234", "An error has occured" );
This could be handled by implementing some facade class for the log4j Logger class.
Have anyone else had similar issue? What was your solution? For now, we prefer the first code example. In the future we might implement the code analyzer to execute during nightly builds (or do anyone know about some existing code analyzer that can be configured to detect a missing text ID from an error() method call?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
避免像这样的复合键:“E1234:发生错误”
我会使用
然后,您可以使用接受错误的方法创建自己的接口:
然后实现它并委托给 log4j 实际日志记录作业。 这将帮助您的开发人员避免出现问题。
Avoid compound keys like this: "E1234:An error has occured"
I would use
Then, you can create your own interface with methods which accept an Error:
Then implement it and delegate to log4j real logging job. This will help your developer avoiding problems.