1

I am adding SLF4J and Logback to my application and I am unsure if I should log the SQL statements that I generate in the repository layer (using Spring JDBC). The level of these statements would of course be set to DEBUG since it could generate a lot of log statements.

Is it common to log SQL statements generated by the application?

1
  • Yeah there is nothing wrong in logging the SQL statements as it might me helpful in case of debugging. But it is advisable to keep it at DEBUG level Commented Mar 31, 2013 at 14:41

3 Answers 3

1

Yes, It is common.

All ORMs, including openjpa and hibernate do it. All mappers like MyBatis have some logging mechanism to hook into any of several logging implementations.

Even in immemorial times. The drivers used to do it when a java.sql.DriverManager#setLogStream was invoked

;)

Sign up to request clarification or add additional context in comments.

Comments

0

I'd write this kind of information to database, keeping statistics so I can query and summarize them.

It's certainly possible to do it with the log, but it's not as easy to summarize as it is from the database. No SQL for log files without extraordinary efforts.

2 Comments

Does it mean that you would not log the SQL if you don't log it to a database?
Logging is done in either case; it's just a choice as to where I put the information. I think a database makes more sense here.
0

Actually if you have a huge application that is considered a financial asset in your point of view, than of course you should log your application since the logging will be considered a security major you can refer to when ever you want. Plus the logging is useful for debugging. But you have to consider which level of logging you want to choose since it will have a huge load on your database if you want log all your SQL statements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.