oracle-r2dbc icon indicating copy to clipboard operation
oracle-r2dbc copied to clipboard

Log SQL parameter values when using spring-boot-starter-data-r2dbc for

Open fascynacja opened this issue 1 year ago • 3 comments

In my project I am using spring-data-r2bc which connects to an Oracle database. My dependencies are:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
    <groupId>com.oracle.database.r2dbc</groupId>
    <artifactId>oracle-r2dbc</artifactId>
    <version>1.2.0</version>
</dependency>

I am using ReactiveCrudRepository in order to retrieve the data:

@Query("SELECT DISTINCT * from PRODUCT prod WHERE  regexp_like (prod.number, (:number) )" )
Flux<Product> findByNumberContaining(String number);

I would like to see in the logs what exact SQL is being executed, along with the values of number. I have followed answers from Log values of query parameters in Spring Data R2DBC?, but nothing seems to work.

I am able to see the SQL, but without the parameter values:

o.s.d.r2dbc.core.NamedParameterExpander  : Expanding SQL statement [SELECT DISTINCT * from PRODUCT  prod WHERE  regexp_like (prod.number, (:number) )] to [SELECT DISTINCT * from PRODUCT prod WHERE  regexp_like (prod.number, (:P0_number) )]
o.s.r2dbc.core.DefaultDatabaseClient     : Executing SQL statement [SELECT DISTINCT * from PRODUCT prod WHERE  regexp_like (prod.number, (:P0_number) )  ]

My current properties are full of different settings which suppose to work for others but not for me:


logging.level.org.hibernate.SQL=DEBUG
logging.level.org.springframework.http.codec.json=INFO
logging.level.org.springframework.web.HttpLogging=INFO
logging.level.org.springframework.r2dbc.core.DefaultDatabaseClient=TRACE
logging.level.org.springframework.r2dbc=TRACE
logging.level.io.r2dbc.postgresql.QUERY= DEBUG
logging.level.io.r2dbc.postgresql.PARAM= DEBUG
logging.level.io.r2dbc.oracle.QUERY= DEBUG
logging.level.io.r2dbc.oracle.PARAM= DEBUG

How can I log the value of the parameter: (:number)?

fascynacja avatar Sep 10 '24 11:09 fascynacja

Oracle R2DBC doesn't include logging. While thelogging.level.io.r2dbc.postgresql.PARAM property may be supported by Postgres R2DBC, but Oracle R2DBC doesn't have an equivalent.

I can see this would be a desirable feature, so let's leave this issue open as a reminder to add it.

Michael-A-McMahon avatar Sep 11 '24 01:09 Michael-A-McMahon

Dear @Michael-Mc-Mahon Thank you for addressing my question. Yes indeed I have seen that Postrges R2DBC has this property to set so I thought there is similiar one in oracle. Thanks for good work, Agata

fascynacja avatar Sep 11 '24 05:09 fascynacja

Oracle R2DBC 1.3.0 updates the Oracle JDBC dependency to 23.6. Users should check out the new diagnosability features available from this release of Oracle JDBC: https://docs.oracle.com/en/database/oracle/oracle-database/23/jjdbc/JDBC-diagnosability.html#GUID-4925EAAE-580E-4E29-9B9A-84143C01A6DC

My hope is that Oracle JDBC logs enough information so that Oracle R2DBC doesn't need to introduce its own log messages. But if that is not the case, we can use this issue/thread to identify what's missing, and think about the best approach for logging in Oracle R2DBC.

Michael-A-McMahon avatar Dec 03 '24 18:12 Michael-A-McMahon