3

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.

How can I configure the application.properties in such a way so that it can be logged ?

Anish B.
  • 9,111
  • 3
  • 21
  • 41

2 Answers2

6

Spring internally logs its caching workflow at a TRACE level. To enable this , in your application.properties file, include the following.

logging.level.org.springframework.cache=TRACE

Dehan
  • 4,818
  • 1
  • 27
  • 38
1

Including the following should help:

logging.level.org.springframework.cache=TRACE
CtrlAltElite
  • 487
  • 8
  • 32