how to log/trace redis calls from java spring app
Asked Answered
B

2

17

I'm looking for the simplest way to log the redis activity originating from my java springboot microservice (queries and responses).

I want to see (in the main springboot log file) log lines whenever data is extracted/inserted from/to redis.

My code use the typical spingframework data redis approach like this:

import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;

@RedisHash
public class InternalAddress {
    private String county;
    private String postcode;
    @TimeToLive
    private Long expiry;
}

*

import org.springframework.data.repository.CrudRepository;

public interface AddressRepository extends CrudRepository<InternalAddress, String> {}

I tried to enable some logging like this.

logging:
  level:
    root: INFO
    redis.clients: TRACE
    org.springframework.data: TRACE

but what i get is totally useless to me: either nothing or just some info about connections being opened or closed...

what i want to see in my log is this really:

2017-11-28T16:05:18.140+00:00 HGETALL key5645 => {...returned data...}
2017-11-28T16:05:25.140+00:00 LPUSH whatever
2017-11-28T16:05:25.140+00:00 HMSET blahblahblah

Any idea? did i miss the right class i should be tracing?

Is there some custom interceptor/listener/aop code i need to write?

Any other approach? Thanks in advance

Bronk answered 28/11, 2017 at 16:47 Comment(0)
B
9

There's no logging available right now. You could implement something yourself but you'd need to augment connection factories with AOP which can be a bit of work. I filed a ticket to address your issue.

Have you tried using Redis' MONITOR command?

Battery answered 2/12, 2017 at 19:38 Comment(4)
Thanks, in the end, i'm going down the AOP route and i have some special code to separate Redis repository calls from let's say Oracle repository calls. It also means what i get is much higher level. things like java method public void delete(String id) or public T findOne(String id).Bronk
@Battery I see the ticket is resolved. Do we have a document? Which version of Data Redis now supports logging?Tectonic
The ticket is closed as “won’t fix”. Why?Tinder
Because there's no simple way to introduce command logging from Spring Data Redis.Battery
G
3

in application.yml/properties file just include below and you could see some related logs

logging:
  level:
    org.springframework.data.*.*: trace
    org.springframework.cache.*: trace
Guillermo answered 12/5, 2022 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.