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

Within Cache abstraction, log when a value was found for a key, and when not. [SPR-11654] #16277

Closed
spring-issuemaster opened this issue Apr 3, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Apr 3, 2014

Brandon Zeeb opened SPR-11654 and commented

We rely heavily on the Spring Cache et al family of abstractions. While the JMX statistics available for some caches are useful, in day to day development and production debugging it's often been essential to know of a particular object was provided by an implementation of Cache or if a backing store (ie: the @Cacheable annotation) was consulted instead.

In short, can we please have some cursory logging at debug level when a value is fetched from a Cache (as in, the key produced a value) and when no value was available? Ideally, the key would be logged in both cases. Optionally, a 3rd log message can be given for the value (with key) at trace level.

I leave it to you to decide where this will go, so long as this is the default behavior.


1 votes, 2 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 4, 2014

Stéphane Nicoll commented

We already log the key (that can be improved) but regarding the cache hit/miss this may become a duplicate log with the caching providers log itself. With regard to cache miss, you can get that information by a log of your own in the annotated method.

We may consider adding a log for a cache hit. Any idea for the format? Thanks!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 29, 2014

Stéphane Nicoll commented

Brandon, any feedback on this one? Thanks.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 29, 2014

Brandon Zeeb commented

In my investigation, there is not an overlap with other providers. I scoured the EhCache source as well as running the root logger at TRACE and did not see any indication of cache hit/miss in the logs. In addition, by using a Spring Cache abstraction, we all hope to remove ourselves from implementation specific Cache provider details, so even if EhCache did have a logger, I would not care.

I do not have a requirement for the specific log format, but within the message it would prefer to see:

  1. The key
  2. Some statement that indicates a value was fetched from the Cache
  3. A string representation of the Cache. This could be a cache name, a cache toString. I don't care so long as it's useful.

An example might be:
Cache ${cache} gave value for key ${key} or
A value was retrieved for key ${key} in Cache ${cache}

I put it to you to devise a log statement format that is consistent with your logging standards and any other existing patterns.

As a second statement, it would be valuable to log the retrieved Value as a String at TRACE level. It would also be preferable to only log the first N bytes or characters of this value. This is an optional requirement, but should also contain the key and cache name.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 7, 2015

Stéphane Nicoll commented

Alright there are two additional TRACE logs for cache hit and cache miss events. Please try 4.2.0.BUILD-SNAPSHOT, available in a couple of hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.