gavlyukovskiy/spring-boot-data-source-decorator

Excessive logging queries

devansh-dalal opened this issue · 5 comments

How to turn off logging or make it debug or trace? I want to retain zipkin tags for queries, though.

Adding

decorator.datasource.datasource-proxy.query.log-level=TRACE

or

decorator.datasource.datasource-proxy.query.enable-logging=false

to my app's spring application properties does not help either. Maybe I am missing some point here

@devansh-dalal can you please provide what setup are you using? Or maybe example of output that you don't want to see?

I have added this library as a dependency in pom.xml for my spring project as

<!-- jdbc datasources decorator autoconfigure Dependency -->
      <dependency>
        <groupId>com.github.gavlyukovskiy</groupId>
        <artifactId>p6spy-spring-boot-starter</artifactId>
        <version>1.6.2</version>
        <scope>import</scope>
      </dependency>

I just wanted export zipkin traces and spy logs as TRACE log-level. Zipkin traces were working perfectly, but query logs were in polluting as they were coming in debug.

1600173789661|104|statement|connection 114|url jdbc:h2:mem:testdb|drop table car_pnr if exists|drop table car_pnr if exists
1600173789662|102|statement|connection 121|url jdbc:h2:mem:testdb|drop table hotel_pnr if exists|drop table hotel_pnr if exists
1600173789662|104|statement|connection 118|url jdbc:h2:mem:testdb|drop table hotel_pnr if exists|drop table hotel_pnr if exists
1600173789662|103|statement|connection 119|url jdbc:h2:mem:testdb|drop table hotel_pnr if exists|drop table hotel_pnr if exists
1600173789662|102|statement|connection 116|url jdbc:h2:mem:testdb|drop table trip if exists|drop table trip if exists
1600173789661|105|statement|connection 112|url jdbc:h2:mem:testdb|drop table car_pnr if exists|drop table car_pnr if exists
1600173789661|103|statement|connection 109|url jdbc:h2:mem:testdb|drop table car_pnr if exists|drop table car_pnr if exists
1600173789661|105|statement|connection 108|url jdbc:h2:mem:testdb|drop table car_pnr if exists|drop table car_pnr if exists
1600173789661|104|statement|connection 110|url jdbc:h2:mem:testdb|drop table car_pnr if exists|drop table car_pnr if exists

I could not use the spy.log file for this setup. I could not figure out any way to change the log-level(to TRACE), I ended up doing:

decorator.datasource.p6spy.enable-logging=false

Oh, the problem is that you're using p6spy as a proxy for your data source, but trying to change properties of datasource-proxy.
Try using

decorator.datasource.p6spy.enable-logging=false

I think there is no way to change log level of p6spy logger, but you can set threshold to log only warnings.

yeah, @gavlyukovskiy , That worked, Thanks.

I was also wondering if there is a way to change the log-level of p6spy logs to TRACE?

@devansh-dalal no, it's not possible. But there is something you can do - raise the threshold for p6spy logs https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-custom-log-levels (<logger-name> is p6spy). You can set it to WARN/ERROR/OFF and less/no logs will be printed.

Essentially it would be the same as disabling all the logging with property above, with only difference that level can be changed dynamically through actuator - https://docs.spring.io/spring-boot/docs/current/actuator-api/html/#loggers-setting-level. It allows you to turn on logging only when you need it without restart of the application.