【问题标题】:Can't turn off hibernate info logging无法关闭休眠信息记录
【发布时间】:2012-01-27 12:03:00
【问题描述】:

我正在使用 log4j 我的配置如下:

log4j.rootLogger=OFF, stdout, rootLog
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.rootLog=org.apache.log4j.RollingFileAppender
log4j.appender.rootLog.File=${user.home}/logs/mylog.log
log4j.appender.rootLog.MaxFileSize=10000KB
log4j.appender.rootLog.MaxBackupIndex=3
log4j.appender.rootLog.layout=org.apache.log4j.PatternLayout
log4j.appender.rootLog.layout.ConversionPattern=%p %t %c - %m%n

# Control/Limit integrated frameworks logging messages

log4j.logger.org.hibernate=OFF
log4j.logger.org.springframework=OFF

虽然我关闭了根记录器和休眠记录

我仍然在控制台中看到以下信息:

2099 [main] INFO org.hibernate.cfg.SettingsFactory
2440 [main] INFO org.hibernate.tool.hbm2ddl.SchemaExport
3239 [main] WARN org.hibernate.util.JDBCExceptionReporter

如何制止,请指教,谢谢。

更新: 记录 jars/依赖项:

       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-simple</artifactId>
         <version>1.5.8</version>
        </dependency>



        <dependency>

            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
             <exclusion>
             <groupId>com.sun.jdmk</groupId>
             <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
             <groupId>com.sun.jmx</groupId>
             <artifactId>jmxri</artifactId>
            </exclusion>
          </exclusions>

        </dependency>

【问题讨论】:

标签: java hibernate jakarta-ee logging log4j


【解决方案1】:

这并不是您的 log4j 配置。您列出的输出与您在配置文件中显示的任何一种转换模式都不匹配。它正在使用其他配置。

更新:根据您更新的问题,如果您使用的是 SLF4J 记录器,那么您甚至没有使用 Log4J,因为您使用的是 slf4j-simple 绑定,它“输出所有事件到 System.err。根据SLF4J manual,仅打印级别为 INFO 及更高级别的消息。要使用 Log4J,您必须使用 slf4j-log4j12 绑定。

【讨论】:

  • 任何想法如何关闭它?
  • 是的,找到正确的 log4j 配置文件并在那里将其关闭。如果您设置了log4j.debug 系统属性,那么 log4j 会告诉您它用于配置的文件。
  • 在哪里设置这个属性 log4j.debug ?
  • 顺便说一句,我只有一个 log4j.properties 文件,那么你在说什么正确的 log4j 文件呢?
  • 在添加它的maven依赖后是否需要做任何额外的配置才能使用slf4j-log4j12,因为在我添加它的依赖并删除slf4j-simple之后我得到了一个例外。
【解决方案2】:

您首先需要找出它使用的是哪个 log4j 配置文件。你可以在log4j上开启debug,作为运行Java时的-D参数,它会告诉你。

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多