开发者

Log4j string matching - callback options

I am using log4j for my app logging. Whenever some error messages are logged, i would like to perform some action like sending socket msg/sending traps/db update. I could see that, in log4j, StringMatchFilt开发者_如何学JAVAer or LevelRange Filter can be used to grep the string. But is it possible to register any callback method with log4j which will be invoked upon any string matching? I guess its possible Jamon tool but dont want use a new framework for this simple feature.


You can register a callback by attaching your own appender. Just make sure to derive from org.apache.log4j.AppenderSkeleton so you only have to implement the append(LoggingEvent) method.

AppenderSkeleton handles the filtering, so you can add the usual <filter> configuration to your appender and your append method will only be called for matching events.


Are those actions part of your business logic or are they just additional ways to store your log info?

If it's part of your business logic, then I think you're trying to attach them at the wrong point.

If you just want more ways to transfer/store your logs, then look at the different Appender implementations there are. There's already a wide array of different Appender versions out there and attaching them at the appropriate logger might just do what you want.

If that's not what you want, please clarify your requirements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜