micronaut-cache icon indicating copy to clipboard operation
micronaut-cache copied to clipboard

@Slf4j breaks with cache annotations

Open j1m-renwick opened this issue 1 year ago • 2 comments

Expected Behavior

the @Slf4j log property to be available in all parts of a class that features cache-related annotations

Actual Behaviour

the @SLF4J log property is sometimes not found in methods that belong to classes that feature cache-related annotations

Steps To Reproduce

  1. run cache-log-bug.zip
  2. observe the error message: groovy.lang.MissingPropertyException: No such property: log for class: com.example.$MyCachedClass$Definition$Intercepted - either by running the unit tests, or by calling the GET APIs featured in MyController.

( NOTE: this seems to occur for other annotations like @CacheInvalidate as well - not just @Cacheable )

Environment Information

Operating System: MacOS Ventura, Version 13.4 JDK Version: Coretto 17

Example Application

see above

Version

4.0.5

j1m-renwick avatar Aug 25 '23 17:08 j1m-renwick

Update: looks like setting a logger explicitly in the class instead of the SLF4J annotation works

e.g. static Logger log = LoggerFactory.getLogger(MyClass) (note the lack of a private keyword)

j1m-renwick avatar Sep 08 '23 16:09 j1m-renwick

Another workaround is to capture the logger in the @Cacheable method, and then use that in the closure

    @Cacheable(cacheNames = "some-cache")
    Single<String> myCachedMethodWithInnerLogging() {
        def logger = log
        Single.just("hi")
            .map{
                logger.info("saying hi!")
                return it
            }
    }

and another is to provide a getter for the log variable

    def getLog() {
        return log
    }

timyates avatar Feb 16 '24 15:02 timyates