We are using Spring with slf4j and hibernate, I’m trying to figure out a way to log exceptions and errors automatically (i.e without initiating an instance of the debugger in each class), so that it may catch any error or exception thrown and also get class and method name in the log,
I read a very short note about using aspects & interceptors for this, so could you provide me with some detailed way to implement this,
Regards,
an exception aspect could look like this:
spring conf:
EDIT:
if you want the logger to log on behalf of the wrapped bean, you could of course do:
or if you prefere the declaring class of this method rather than the actual (potentially proxied/auto-generated type):
Honestly, I can’t estimate the performance implications of calling LoggerFactory.getLogger(..) every time. I’d assume that it shouldn’t be too bad, as exceptions are exceptional (i.e. rare) anyway.