0

I have set

logging.level.org.hibernate.type.descriptor.sql=trace

but it logs each variable binding as a separate line which, having average 50-60 columns per table makes log files harder to understand.


Is there a way to configure logger so that all hibernate queries are printed with its already bound values. (which will need only a single line in the log file.)

  • I'm not sure if that works, but you could look at using logback.xml to use the logstash encoder `` and using the dependencies for logstash encoder (see https://github.com/logstash/logstash-logback-encoder/tree/logstash-logback-encoder-6.2 for documentation of latest version). Having json as output is not well human readable, but you can index the logfiles, and make them searchable, and there are tools out there, that help with viewing. – Frischling Nov 01 '19 at 07:44

2 Answers2

0

As far as I know, logging SQL with bounded value has once been a feature in Hibernate (2.x or 3.x?) but was later removed.

One workaround is to use utilities like JdbcDsLog ( e.g. https://github.com/adrianshum/jdbcdslog )

Disclaimer: I was the maintainer of the above fork of JdbcDsLog

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
0

I have found best way to do this is to use either datasource proxy. These are invoked before each db hit. And we can set our logic to log the query with them.

A known example of datasource proxy is p6spy.