Search code examples
javaannotationstapestryslf4j

Does an annotation exist for slf4j like the @Log for Tapestry?


There is an annotation @Log in the Tapestry fwk which traces, with debug level, the entry and exit of a method.

Is there the same thing for slf4j ?


Solution

  • This seems like an unlikely functionality to be packaged with a logging framework.

    Tapestry's @Log annotation works via its AOP mechanism. Component classes and templates are transformed and advised according to the various annotations on the various fields and methods when they are loaded, which is also how the @Log functionality works (via the LogWorker transformation worker, which looks for the annotation on the component's methods and wraps the method invocations, putting the actual invocation between logging statements).

    An annotation packaged with SLF4j would have to do a similar thing, which would be a highly invasive and unpractical thing to do for so little functionality.

    If, however, your project uses AOP (e.g. via AspectJ), you could just create your own logging annotation and advice, calling the appropriate SLF4j methods.