4

I have a hibernate that is configured only programmatically ( I don't have a single XML file ).

I just finished writing my own implementation of org.slf4j.Logger.
How can I force hibernate to log to my implementation instead of the default one?

iliaden
  • 3,791
  • 8
  • 38
  • 50

1 Answers1

1

AFAIK you can't just change hibernates logging behaviour, but you can get slf4j to use your source with slf4j 'Bridging legacy APIs'

Ok if you re-implemented a slf4j logger, you are using the slf4j-api right ? if you are using Maven you could alter the dependencies for your project (see e.g. hibernate slf4j dependencies) to use your implementation jar instead

Community
  • 1
  • 1
Michael Pralow
  • 6,560
  • 2
  • 30
  • 46
  • thanks, but I still can't figure out how to make slf4j use a custom implementation, rather than an already created one (jcl, log4j, jul). – iliaden Jun 20 '11 at 14:35
  • I'm following the instructions from http://www.slf4j.org/faq.html#slf4j_compatible . However, they require me to implement a `StaticLoggerBinder` class. Does it mean I have to download the entire source and rewrite the StaticLoggerBinder, or is there another approach? – iliaden Jun 20 '11 at 17:18
  • 1
    you could fork [slf4j-simple](https://github.com/ceki/slf4j/tree/master/slf4j-simple/src/main/java/org/slf4j/impl), you only need to create the factory and change the StaticLoggerBinder – Michael Pralow Jun 20 '11 at 17:40
  • I sitll cannot figure out how to get Hibernate to use my `StaticLoggerBinder` instead of the default one, present in slf4j-api.jar – iliaden Jun 20 '11 at 18:08
  • reading [slf4j-api LoggerFactory](https://github.com/ceki/slf4j/blob/master/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java#L118) i guess it should just work, either slf4j prints an error msg and uses the standard StaticLoggerBinder or it uses your version – Michael Pralow Jun 20 '11 at 20:03
  • actually the provided StaticLoggerBinder should never work, see [slf4j-api StaticLoggerBinder](https://github.com/ceki/slf4j/blob/master/slf4j-api/src/main/java/org/slf4j/impl/StaticLoggerBinder.java#L62) – Michael Pralow Jun 20 '11 at 20:06
  • I wrote my own. I only had a small issue - it needed to be part of the org.slf4j.impl package. Once I moved everything to that package, the loggs were transfered to my logger implementation – iliaden Jun 20 '11 at 20:37