6

My application uses H2 but already has a log file (ex: abc.log)

Now, I'm trying to make even the H2 to write logs/errors to that file (abc.log) so if something goes wrong an user has only 1 file to send to me (not abc.log AND abc.db.trace file)

Is there a way to achieve that?

2 Answers 2

5

You can configure H2 to use SL4FJ as follows:

jdbc:h2:~/test;TRACE_LEVEL_FILE=4

The logger name is h2database.

7
  • Thank you for you quick reply. Can you give more info of how to proceed. As far as I see I do need to use sl4fs and search for that h2database logger (with LoggerFactory.getLogger('h2database '))...but from there? Thanks
    – Alex
    Commented Jan 4, 2013 at 13:19
  • 1
    That's it, you just use SLF4J configure a logger for "h2database". For more information about SLF4J, see the SLF4J web site. Commented Jan 4, 2013 at 13:28
  • I do see now that a new folder is create [trace.db] in app's folder. How can I remove/disable it?
    – Alex
    Commented Jan 7, 2013 at 10:05
  • 1
    And you did append ;TRACE_LEVEL_FILE=4 to the database URL? What is your database URL? Commented Jan 7, 2013 at 15:23
  • I do use different connection URLs, one for development and one for development conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/test;TRACE_LEVEL_FILE=4", "sa", ""); and one for release conn = DriverManager.getConnection("jdbc:h2:" + f.getCanonicalPath() + ";TRACE_LEVEL_FILE=4", "sa", "");
    – Alex
    Commented Jan 8, 2013 at 5:15
3

Ok the solution was to simple for me to believe it but the only thing I had to do is to add

slf4j-api-1.7.2.jar 

and

slf4j-jdk14-1.7.2.jar 

in my app's classpath.

As SLF4J will (first search and then) discover by itself what underlying logging framework to use it is simply a matter of placing the right implementation.

One warning, it seems that SLF4J can not use more than one frameworks at a time so this solution work ONLY if you have a single existing framework.

Not the answer you're looking for? Browse other questions tagged or ask your own question.