Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Slf4j breaks with cache annotations #655

Open
j1m-renwick opened this issue Aug 25, 2023 · 2 comments
Open

@Slf4j breaks with cache annotations #655

j1m-renwick opened this issue Aug 25, 2023 · 2 comments
Assignees
Labels
info: workaround available A workaround is available for the issue lang: groovy Issues or features specific to Groovy

Comments

@j1m-renwick
Copy link

j1m-renwick commented Aug 25, 2023

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
Copy link
Author

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)

@sdelamo sdelamo added the lang: groovy Issues or features specific to Groovy label Jan 15, 2024
@timyates
Copy link
Member

timyates commented Feb 16, 2024

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
    }

@sdelamo sdelamo added the info: workaround available A workaround is available for the issue label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: workaround available A workaround is available for the issue lang: groovy Issues or features specific to Groovy
Projects
Status: No status
Development

No branches or pull requests

3 participants