关闭stdout

时间:2015-04-22 11:19:50

标签: java hibernate maven jar log4j

请阅读完整的问题,然后考虑重复的可能性。

我在stackoverflow上经历了几个问题,他们提出了关闭stdout上的hibernate日志记录的方法。

当我使用stdout运行应用程序的jar文件(maven)时,我可以成功关闭mvn exec:java -Dexec.mainClass="org.flytxt.JobMonitor"上的hibernate日志记录。这是通过使用log4j.prpoerties文件来实现的。

使用stdout显示maven上的输出:

enter image description here

但是当我使用由maven打包的相同jar文件时(可以在项目目录的target子目录中找到),手动将所有jar添加到MANIFEST.MF并执行它({ {1}}),我在java -jar JobMonitor-1.0-SNAPSHOT.jar上看到了太多关于hibernate的DEBUG日志信息,如下所示:

stdout

我的应用程序使用root@fly-dt223:/home/rohit/workspace_dfe/JobMonitor/JobMonitor/daemon# java -jar JobMonitor-1.0-SNAPSHOT.jar 17:00:41.954 [192.168.151.50] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider 17:00:41.965 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@1ef8deca 17:00:41.965 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration boolean -> org.hibernate.type.BooleanType@1ef8deca 17:00:41.965 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Boolean -> org.hibernate.type.BooleanType@1ef8deca 17:00:41.966 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration numeric_boolean -> org.hibernate.type.NumericBooleanType@1ce2a846 17:00:41.967 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration true_false -> org.hibernate.type.TrueFalseType@1ce7df90 17:00:41.967 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration yes_no -> org.hibernate.type.YesNoType@40d2a14b 17:00:41.968 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration byte -> org.hibernate.type.ByteType@2b6167ab 17:00:41.968 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration byte -> org.hibernate.type.ByteType@2b6167ab 17:00:41.968 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Byte -> org.hibernate.type.ByteType@2b6167ab 17:00:41.969 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration character -> org.hibernate.type.CharacterType@6ba47ef5 17:00:41.969 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration char -> org.hibernate.type.CharacterType@6ba47ef5 17:00:41.969 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Character -> org.hibernate.type.CharacterType@6ba47ef5 17:00:41.970 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration short -> org.hibernate.type.ShortType@39614c6 17:00:41.971 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration short -> org.hibernate.type.ShortType@39614c6 17:00:41.972 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration java.lang.Short -> org.hibernate.type.ShortType@39614c6 17:00:41.973 [192.168.151.50] DEBUG org.hibernate.type.BasicTypeRegistry - Adding type registration integer -> org.hibernate.type.IntegerType@1621a02b ,其内容如下所示。

log4j.properties

maven似乎从jar文件本身或从其他路径加载log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=/tmp/hibernate.log log4j.appender.file.MaxFileSize=10MB 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 log4j.rootLogger=INFO, file log4j.logger.org.hibernate=INFO log4j.logger.org.hibernate.type=INFO 文件。 以下是项目目录结构中log4j.properties文件的位置:

enter image description here enter image description here

所以,我的问题是:当我使用log4j.properties时,如何停止hibernate登录stdout并使其登录到上面显示的文件log4j.properties的内容中指向的文件中java -jar JobMonitor-1.0-SNAPSHOT.jar 1}}?

我认为,使用命令log4j.properties时,我的应用程序可能无法找到java -jar JobMonitor-1.0-SNAPSHOT.jar

0 个答案:

没有答案