[英]How to log cache hits through @Cacheable annotation?
There is a method in a class like this down below :下面的类中有一个方法:
@Override
@Transactional
@Cacheable(value = "products", key = "#id")
public Product getProduct(long id) throws ApplicationException {
Product product = null;
try {
ProductEntity productEntity = productDAO.getProduct(id);
product = productTransformer.toProduct(productEntity);
} catch (SystemException ex) {
throw new ApplicationException(ex.getCode(), ex.getMessage(), "Problem in DataLayer", "Data Layer Error",
new Object[] { ex });
}
return product;
}
The application is working fine.该应用程序运行良好。 But I want to have a cache hit log when data is put into the cache.
但是我想在数据放入缓存时有一个缓存命中日志。 I want to log it through log4j.properties.
我想通过 log4j.properties 记录它。
How can I configure the application.properties in such a way so that it can be logged ?如何以这种方式配置 application.properties 以便它可以被记录?
Spring internally logs its caching workflow at a TRACE level. Spring 在内部以 TRACE 级别记录其缓存工作流。 To enable this , in your application.properties file, include the following.
要启用此功能,请在您的 application.properties 文件中包含以下内容。
logging.level.org.springframework.cache=TRACE
包括以下内容应该会有所帮助:
logging.level.org.springframework.cache=TRACE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.