简体   繁体   English

log4j自定义类别实现

[英]log4j Custom Category Implementation

What is the easiest way to implement a custom category class for log4j? 为log4j实现自定义类别类的最简单方法是什么? Here is what I'm trying to achieve: 这是我要实现的目标:

  1. Use log4j to send notifications using a custom built notification application. 使用log4j通过自定义构建的通知应用程序发送通知。

  2. Use the vanilla log4j library without having to fork and build a custom jar. 使用vanilla log4j库,而无需派生和构建自定义jar。

I want to overload the info() , warn() , error() , fatal() methods by adding 2 more parameters like this: error(Object message, Throwable t, String alertLevel, String alertGroup) . 我想通过添加其他2个这样的参数来重载info()warn()error()fatal()方法: error(Object message, Throwable t, String alertLevel, String alertGroup)

I want to do this because I want to log and alert the same message in one call while still having the flexibility of logging and alerting in different levels. 我想要这样做是因为我想在一个呼叫中记录和提醒同一条消息,同时仍具有在不同级别进行记录和提醒的灵活性。

I did many searches and looked through the apache log4j configuration tutorial and came up empty handed. 我进行了许多搜索,并浏览了apache log4j配置教程,空手而归。 I also realize there might be a better way to approach this. 我也意识到可能有更好的方法来解决此问题。 Can you someone show me the way please? 有人可以给我指路吗?

This isn't what you are asking for, but you may want to look into Mapped Diagnostic Context . 这不是您要的内容,但是您可能需要研究“ 映射的诊断上下文”

Some information about can be found on http://www.slf4j.org/manual.html#mdcz 有关的一些信息可以在http://www.slf4j.org/manual.html#mdcz中找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM