Hibernate 4.1.1使用GlassFish Server下的log4j(1.2.17)和sl4fj(1.7.2)进行日志记录

时间:2012-10-17 17:03:37

标签: hibernate glassfish log4j slf4j

Dudes,我正在使用hibernate 3.5和log4j以及slf4。它正在工作,记录和绑定参数值。所以我更新了hibernate for 4.1.1版本,之后log4不会记录有关hibernate的任何信息(并且不显示SQL参数值)。我知道新版本使用jboss日志记录,但我试图删除并且不起作用。我正在使用GlassFish 3.1.1.2(build5)。在我的库中,我有:

-commons-logging
-slf4j-log4j
-log4j(1.2.17)
-slf4j-api(1.7.2)

关注我的log4j.properties和hibernate.cfg

hibernate.cfg

<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>

log4.properties

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\teste.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO

log4j.logger.org.hibernate.type=ALL
log4j.logger.org.hibernate.jdbc=trace

所以,它可以用于其他事情,你可以看到我的teste.log:

13:52:36,692  INFO AbstractTilesApplicationContextFactory:76 - Initializing Tiles2     application context. . .
13:52:36,707  WARN ChainedTilesApplicationContextFactory:117 - Cannot find    TilesContextFactory class   org.apache.tiles.portlet.context.PortletTilesApplicationContextFactory
13:52:36,707  INFO AbstractTilesApplicationContextFactory:95 - Finished initializing Tiles2 application context.
13:52:36,708  WARN ChainedTilesApplicationContextFactory:117 - Cannot find TilesContextFactory class org.apache.tiles.portlet.context.PortletTilesApplicationContextFactory
13:52:36,770  WARN TilesContainerFactory:365 - DEPRECATION WARNING! You are using parameter-based initialization, that is no longer supported! Please see docs:  http://tiles.apache.org/framework/tutorial/configuration.html
13:52:36,771  INFO TilesContainerFactory:372 - Initializing Tiles2 container. . .
13:52:36,774  WARN ChainedTilesApplicationContextFactory:117 - Cannot find TilesContextFactory class org.apache.tiles.portlet.context.PortletTilesApplicationContextFactory
13:52:36,780  INFO ChainedTilesRequestContextFactory:105 - Cannot find TilesRequestContextFactory class org.apache.tiles.portlet.context.PortletTilesRequestContextFactory, skipping support for the managed platform
13:52:36,836  WARN BaseLocaleUrlDefinitionDAO:209 - Unable to find configured definition '/WEB-INF/tiles.xml'
13:52:36,907  INFO TilesContainerFactory:382 - Tiles2 container initialized
13:52:36,909  INFO TilesAccess:113 - Publishing TilesContext for context: org.apache.tiles.servlet.context.ServletTilesApplicationContext

但是,hibernate在服务器stdout中显示信息如下。我不知道hibernate用于显示它,如果我删除jboss日志记录,它会继续显示

Informações: Hibernate: 
select
    this_.cobs_id as cobs1_5_0_,
    this_.cobs_attributes as cobs2_5_0_,
    this_.cobs_description as cobs3_5_0_,
    this_.cobs_name as cobs4_5_0_,
    this_.cobs_position as cobs5_5_0_,
    this_.cobs_sequence as cobs6_5_0_,
    this_.cobs_status as cobs7_5_0_,
    this_.cobs_template as cobs8_5_0_,
    this_.cobs_cosi_id as cobs9_5_0_ 
from
    core.core_blocks this_ 
where
    this_.cobs_cosi_id=? 
    and not exists (
        select
            1 
        from
            core.core_groups_blocks 
        where
            this_.cobs_id=cogb_cobs_id
    ) 
order by
    this_.cobs_sequence asc
Informações: Hibernate: 

检查我的服务器stdout我发现了这个:

Informações: HHH000046: Connection properties: {user=root, password=****}
Informações: HHH000006: Autocommit mode: false

可能hibernate正在使用其他日志来注册信息,但我找不到它

1 个答案:

答案 0 :(得分:0)

显然这个问题是由GlassFish 3.1.2.2引起的,我安装了glassfish 3.1.2并修复了问题