Log4j - org.hibernate.type doesn't work!

2019-02-01 23:26发布

问题:

This is my logger configuration:

log4j.logger.org.hibernate.SQL=TRACE, stdout
log4j.logger.org.hibernate.type=TRACE, stdout

but I don't see type bingings

So I tried this

log4j.logger.org.hibernate=TRACE, stdout

to see if I missed something (this shows all hibernate loggers) and I found out that the org.hibernate.engine.QueryParameters logger also shows parameter bindings (still no sign of org.hibernate.type logger binding messages)

So then I tried

log4j.logger.org.hibernate.SQL=TRACE, stdout
log4j.logger.org.hibernate.type=TRACE, stdout
log4j.logger.org.hibernate.engine.QueryParameters=TRACE, stdout

but it shows me only logs from the org.hibernate.SQL logger!

We use Hibernate 3.2.6.ga with classic query translator

Any clues?

回答1:

i use this for hibernate log

### Hibernate logging configuration ###  

### Log everything (a lot of information, but very useful for troubleshooting) ###  
#log4j.logger.org.hibernate=info  

### Log HQL and SQL ASTs during query parsing ###  
log4j.logger.org.hibernate.hql.ast.AST=DEBUG, SQL_APPENDER  
log4j.additivity.org.hibernate.hql.ast.AST=false  

### log just the SQL  
log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER  
log4j.additivity.org.hibernate.SQL=false  

### log JDBC bind parameters. Very userfull, when debug parameterized queries ###  
log4j.logger.org.hibernate.type=TRACE, SQL_APPENDER  
log4j.additivity.org.hibernate.type=false  

### log schema export/update ###  
#log4j.logger.org.hibernate.tool.hbm2ddl=info  

### log HQL parse trees  
#log4j.logger.org.hibernate.hql=debug  

### log cache activity ###  
#log4j.logger.org.hibernate.cache=info  

### log transaction activity  
#log4j.logger.org.hibernate.transaction=debug  

### Log all JDBC resource acquisition  
#log4j.logger.org.hibernate.jdbc=debug  

### enable the following line if you want to track down connection ###  
### leakages when using DriverManagerConnectionProvider ###  
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace  

log4j.appender.SQL_APPENDER=org.apache.log4j.RollingFileAppender  
log4j.appender.SQL_APPENDER.File=c\:/EC_sql.log
log4j.appender.SQL_APPENDER.MaxFileSize=1000KB  
log4j.appender.SQL_APPENDER.MaxBackupIndex=62  
log4j.appender.SQL_APPENDER.layout=org.apache.log4j.PatternLayout  
log4j.appender.SQL_APPENDER.layout.ConversionPattern=[%d] %5p [%t] (%F:%L) - %m%n

you can comment or uncomment several options

Attention: your webapp will be a lot slower when you use this. so only use it for debugging



回答2:

It think it is a bug, take a look at HHH-2835



回答3:

I faced the same problem with hibernate 3.5.5 and I found out that tracing is enabled by static field in org.hibernate.type.NullableType in the following way:

private static final boolean IS_VALUE_TRACING_ENABLED = LoggerFactory.getLogger( StringHelper.qualifier( Type.class.getName() ) ).isTraceEnabled();

So I set in log configuration log level TRACE for org.hibernate.type.Type and restarted a server.

<logger name="org.hibernate.type.Type" level="TRACE">
    <appender-ref ref="myAppender"/>
</logger>