Reputation: 264
My application uses hibernate and its printing lot of logging. I tried to set logging to error level as below. However, it does not set hibernate logging to error level. Is anything missing here?
pom.xml :
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.11.2</version>
</dependency>
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout
pattern="[%d{dd MMM yyyy HH:mm:ss}] [%-5p] [%t] [%C{1}:%M:%L] - %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.myapp" level="error" additivity="false">
<AppenderRef ref="CONSOLE" />
</Logger>
<Root level="info">
<appender-ref ref="CONSOLE" />
</Root>
<Logger name="org.hibernate" level="error" additivity="false">
<AppenderRef ref="CONSOLE" />
</Logger>
</Loggers>
</Configuration>
Hibernate and spring version used :
<spring-framework.version>4.0.3.RELEASE</spring-framework.version>
<hibernate.version>3.6.9.Final</hibernate.version>
Log its printing
19:05:16.733 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.h.hql.ast.QueryTranslatorImpl - HQL: SELECT g FROM myClass g
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.h.hql.ast.QueryTranslatorImpl - SQL: sql sample
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.hibernate.impl.SessionFactoryImpl - Checking named query: Underlyer.findAll
19:05:16.735 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.h.hql.ast.QueryTranslatorImpl - parse() - HQL: SELECT u FROM entity.class1 u
19:05:16.737 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.hql.ast.AST - --- HQL AST ---
\-[QUERY] Node: 'query'
\-[SELECT_FROM] Node: 'SELECT_FROM'
+-[FROM] Node: 'FROM'
| \-[RANGE] Node: 'RANGE'
| +-[DOT] Node: '.'
| | +-[DOT] Node: '.'
| | | +-[DOT] Node: '.'
| | | | +-[DOT] Node: '.'
| | | | | +-[DOT] Node: '.'
| | | | | | +-[DOT] Node: '.'
Upvotes: 5
Views: 2229
Reputation: 147
Set the hibernate Configuration properties:
hibernate.show_sql=false
Upvotes: 1
Reputation: 309
What seems that your logger is not picking the right file configuration, there might be two reasons.
<Root level="info">
<appender-ref ref="CONSOLE" />
</Root>
to
<Root level="info">
<AppenderRef ref="CONSOLE" />
</Root>
The above two identified reasons are from the logging pattern you are using in your log4j2.xml and actual logs shared are totally different. Look your desired pattern layout from log4j2.xml
<PatternLayout pattern="[%d{dd MMM yyyy HH:mm:ss}] [%-5p] [%t] [%C{1}:%M:%L] - %m%n" />
It should print logs looks like
[16 Apr 2020 19:05:16.733] [...] [...] [...:...:...] - .......
where actual logs have different patterns.
19:05:16.733 [...] ... ....... - .....
as mentioned under.
19:05:16.733 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG org.hibernate.hql.ast.ErrorCounter - throwQueryException() : no errors
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.h.hql.ast.QueryTranslatorImpl - HQL: SELECT g FROM myClass g
19:05:16.734 [[ACTIVE] ExecuteThread: '18' for queue: 'weblogic.kernel.Default (self-tuning)'] DEBUG o.h.hql.ast.QueryTranslatorImpl - SQL: sql sample
Upvotes: 0
Reputation: 2779
Is it a Spring application if so you could hide SQL from printing via properties file option:
spring.jpa.show-sql=false
If it is not a Spring you could try this (in Sprint apllication such Hibernate log config works):
<Logger name="org.hibernate.SQL" level="error"/>
<Logger name="org.hibernate.type" level="error"/>
OR whatever Log Level do you want.
Upvotes: 1
Reputation: 2785
The thread names seem to suggest that you're running on a weblogic container. Are you sure that the logging config is being used at all? (e.g. see log4j2-not-working-in-weblogic-12-2-1).
Apart from that, I also don't see the point in using additivity="false" and then repeating exactly the same appenders. Why don't you prefer something simpler like this?
<Loggers>
<Root level="info">
<appender-ref ref="CONSOLE" />
</Root>
<Logger name="com.myapp" level="error"/>
<Logger name="org.hibernate" level="error"/>
</Loggers>
Upvotes: 6