JDBC logging to file

前端 未结 6 561
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 02:43

I need to log all the queries to an Oracle database in my project to a log file.

What would be a good solution to achieve this? Some sample usage would be a

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 02:58

    You configure where log messages are written by configuring where the underlying logging engine is sending them. Since you're talking about slf4j, that means you've got to configure the thing that it is bridging to (the java.util.logging system in your case; called JUL henceforth).

    Unfortunately, JUL is among the more confusing systems to configure. Here's where I'll just cut to the chase. Create a file in your deployed classpath called logging.properties (I think; this is one of the confusing bits) which contains something like this:

    handlers=java.util.logging.FileHandler
    .level=ALL
    java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
    

    The documentation on the FileHandler class describes things that you can configure.

提交回复
热议问题