There is not something like that currently in log4cxx or log4j. I think it would be a bad thing to make your application behavior dependent upon log4cxx. For example, if this user configured the hierarchy threshold to OFF the exception would no longer available.

In your particular case, you could do a couple of things:

1. Capture the exception outside of log4cxx
2. Redefine the appropriate LOG4CXX_ macros so that they also capture the message to an external source. If you are only interested in ERROR level messages, then you could have an include file that does something like:

#undef LOG4CXX_ERROR
#define LOG4CXX_ERROR(logger, msg) \
MyErrorCache::setLastError(msg); \
body of original LOG4CXX_ERROR

3. Write a custom appender that captures the logging event and attach it to root, then query the appender. This would require that the logging request would get down to the root logger which would not happen if threshold was set to OFF or a logger had set "additivity" to false.

Reply via email to