1

So I have a project where I'm using Wildfly 10 and Hibernate 5.2.9 and I'm trying to log the hibernate stuff, such as Queries and so on, using Log4J2, but for some reason it's not working Log4J2 works when I log application stuff like log.info("SOMETHING")... I post here my log42j.xml file

<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns="http://logging.apache.org/log4j/2.0/config">

<Appenders>
    <Appender type="FILE" name="FF" fileName="C:/logs/logfile.log">
        <Layout type="type" pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | %C{2} 
(%F:%L) - %m%n"
    </Appender>
</Appenders>

<Loggers>
    <Logger name="my.java.package" level="DEBUG">
        <AppenderRef ref="FILE"></AppenderRef>
    </Logger>
    <Logger name="org.hibernate.type" level="TRACE">
        <AppenderRef ref="FILE"></AppenderRef>
    </Logger>
    <Logger name="org.hibernate.SQL" level="TRACE">
        <AppenderRef ref="FILE"></AppenderRef>
    </Logger>
    <Logger name="org.hibernate" level="TRACE">
        <AppenderRef ref="FILE"></AppenderRef>
    </Logger>

    <Root level="ALL">
        <AppenderRef ref="FILE"/>
    </Root>
</Loggers>

</Configuration>

Any thoughts of how can I solve this? Thanks!

GoAlves
  • 435
  • 3
  • 5
  • 16
  • possible duplicate: https://stackoverflow.com/questions/436276/configuring-hibernate-logging-using-log4j-xml-config-file – K.Nicholas May 31 '17 at 14:13
  • I know it may seem like a duplicate, but I had already been through that post and others and I still got nowhere. That's why I posted my specific case =) – GoAlves May 31 '17 at 14:29

1 Answers1

1

Since Hibernate is a module provided by the server it uses the servers logging configuration, not the configuration supplied in your deployment.

Really you wouldn't want Hibernate using your log configuration anyway. If you had multiple deployments, each having their own logging configuration there is no guarantee which configuration would win when configuring the logging.

James R. Perkins
  • 16,800
  • 44
  • 60
  • I wasn't seeing it that way, but I think you're right. It's best to just let Hibernate use the logging configuration of the server, since it would probably generate a lot of overhead in my log file mixed with the application logs which are the most important IMO. Thanks! – GoAlves Jun 02 '17 at 09:45