I have recently added hibernate to my pom.xml, and it is working fine. However, the logging is irritating and i'm not sure how to turn it off or limit the level of it (I don't even know exactly what it has included to start all this logging). I am new to this, to maven and to hibernate.
Here is my pom.xml dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
</dependencies>
The log starts like this:
21:17:15.115 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@ba4d54
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@ba4d54
21:17:15.130 [main] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@ba4d54
I have tried adding a log4j.properties file to my resources and it didn't seem to change anything. I also tried simplelog.properties (following other SO posts which haven't helped). I'm a bit stuck here, help would be really appreciated. Ideally, i'd like to just set the logger to off, or just the mysql queries.
This is the dependency tree:
[INFO] org.springframework:gs-rest-service:jar:0.1.0
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.1.10.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.1.10.RELEASE:compile
[INFO] | | | +- org.slf4j:jcl-over-slf4j:jar:1.7.7:compile
[INFO] | | | | \- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] | | | +- org.slf4j:jul-to-slf4j:jar:1.7.7:compile
[INFO] | | | +- org.slf4j:log4j-over-slf4j:jar:1.7.7:compile
[INFO] | | | \- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.13:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.1.10.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:7.0.57:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:7.0.57:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:7.0.57:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:7.0.57:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.4:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.4:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.3.4:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.0.3.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] | +- org.springframework:spring-core:jar:4.0.8.RELEASE:compile
[INFO] | +- org.springframework:spring-web:jar:4.0.8.RELEASE:compile
[INFO] | | +- org.springframework:spring-aop:jar:4.0.8.RELEASE:compile
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.0.8.RELEASE:compile
[INFO] | | \- org.springframework:spring-context:jar:4.0.8.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.0.8.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.0.8.RELEASE:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.0.1.Final:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO] | +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate.common:hibernate-commons-annotations:jar:tests:4.0.1.Final:compile
[INFO] \- mysql:mysql-connector-java:jar:5.1.10:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.918 s
[INFO] Finished at: 2015-02-07T22:09:37+00:00
[INFO] Final Memory: 20M/203M
[INFO] ------------------------------------------------------------------------
The solution was to add a configuration file named "logback.xml" in the resources folder of the project. The contents of this file are:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding.
The jboss-logging jar is a required dependency of Hibernate and therefore will always need to be on the classpath.
1.1 Hibernate Object-Relational Mapping or ORM is the programming technique to map application domain model objects to the relational database tables. Hibernate is Java-based ORM tool that provides the framework for mapping application domain objects to the relational database tables and vice versa.
You probably have a global DEBUG
log level set in your logging framework configuration.
All you need to do is setting the org.hibernate
log level to WARN
or ERROR
instead:
Logback/Log4j2
<logger name="org.hibernate" level="warn"/>
Log4j
<logger name="org.hibernate">
<level value="warn"/>
</logger>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With