Log4j String Matching - Callback Parameters

I use log4j to register applications. Whenever some error messages are logged, I would like to perform some actions, such as sending msg socket / sending traps / db updates. I could see that in log4j a StringMatchFilter or LevelRange filter can be used to grep a string. But is it possible to register any callback method with log4j that will be called during any string matching? I guess its possible Jamon tool, but don't want to use the new structure for this simple function.

+3
source share
2 answers

You can register a callback by adding your own appender. Just make sure it's derived from org.apache.log4j.AppenderSkeleton, so you need to implement the method append(LoggingEvent).

AppenderSkeletonhandles filtering, so you can add the usual configuration <filter>to your application, and the method appendwill only be called to match events.

+2
source

Are these actions part of your business logic, or are they just additional ways to store information about your journal?

If this is part of your business logic, then I think you are trying to attach them at the wrong point.

/ , Appender . Appender , .

, , .

+1

All Articles