1

Currently I'm working with the Spring Boot project where properties are defined in the YML file, like that:

logging:
  level:
    org:
      hibernate:
            SQL: DEBUG

What I need to do is to retrieve the message from the debug log (to be specific: a query which is executed by Hibernate after hitting particular endpoint) and save that message as a String value, to the DB.

I tried with the following:

@Value("${logging.level.org.hibernate.SQL}")
private String logMessage;

Unfortunately, with that I can only display "DEBUG" String.

After I changed the @Value like this...

@Value("${logging.level.org.hibernate.SQL.DEBUG}")
private String logMessage;

...I got an error.

Can you please advise me on how to write it down in a correct manner, to see the exact message from the debug log?

Or maybe there are some better ways to achieve that?

I've already tried with requestLoggingFilter() method, but I couldn't find any option to retrieve the exact Hibernate (SQL) query with that...

Thank you in advance for any help!

Kind regards, Matt

JavaMat87
  • 33
  • 1
  • 7

1 Answers1

0

Usually logging is configured to write messages to the standard out (which is usually a console) and to a log file. I'd suggest you to define a new log appender that will write log entries to the database.

An example of configuration you can find for instance here.

mentallurg
  • 4,967
  • 5
  • 28
  • 36
  • Thanks mentallurg! I went few steps further with your hint and now I got a new portion of dillemas... ;] If you're curious enough what are they, you can check it out at this post: https://stackoverflow.com/questions/62717600/log4j-2-in-spring-boot-jdbc-appender-doesnt-write-log-messages-to-the-dbs-col – JavaMat87 Jul 03 '20 at 21:24