0

Please read complete question and then think of the possibility of being duplicate.

I have gone through several question on stackoverflow and they suggested ways to turn off hibernate logging on stdout.

I could successfully turn off hibernate logging on stdout when I use maven to run the jar file of my application (mvn exec:java -Dexec.mainClass="org.flytxt.JobMonitor"). This was achieved by using log4j.prpoerties file.

The output on stdout by using maven shown below:

enter image description here

But when I use the same jar file packaged by maven (can be found in the target subdirectory of the project directory), add all jars into the MANIFEST.MF manually and execute it (java -jar JobMonitor-1.0-SNAPSHOT.jar), I see too much DEBUG logging info of hibernate on stdout like show below:

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

My application uses log4j.properties and its content is shown below.

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

It appears that maven is loading log4j.properties file from either the jar file itself or from the other path. Below are the locations of log4j.properties file within my project directory structure:

enter image description here enter image description here

So, my question is: How can I stop hibernate to log on stdout and make it log into a file as pointed in the content of the file log4j.properties shown above when I use simply java -jar JobMonitor-1.0-SNAPSHOT.jar ?

I assume, it is likely that my application could not locate log4j.properties while using the command java -jar JobMonitor-1.0-SNAPSHOT.jar.

Rohit
  • 604
  • 1
  • 10
  • 25
  • possible duplicate of [Turning off hibernate logging console output](http://stackoverflow.com/questions/311408/turning-off-hibernate-logging-console-output) –  Apr 22 '15 at 11:35
  • I mentioned in my question that I could turn off logging onto `stdout` using maven executor but I could not turn it off when I use `java -jar JobMonitor-1.0-SNAPSHOT.jar`. Some answers in the link you provide would work but I dont want my application to stop logging programmatically. – Rohit Apr 22 '15 at 11:41

0 Answers0