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, StringMatchFilter 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.
Share
You can register a callback by attaching your own appender. Just make sure to derive from
org.apache.log4j.AppenderSkeletonso you only have to implement theappend(LoggingEvent)method.AppenderSkeletonhandles the filtering, so you can add the usual<filter>configuration to your appender and yourappendmethod will only be called for matching events.