Friday 17 March 2017

How can I disable application context info in log or console

How can I disable application context info in log or console

Visit my previous post, Step wise how to implement spring logging with log4j.

When implement spring logging with log4j, logger prints all application context info on console and file, which I don't want. I want disable application context info in log or console.

Log4J dependency

//LOG4J
    compile 'log4j:log4j:1.2.17'
    compile 'log4j:apache-log4j-extras:1.2.17'

log4j.properties


# LOG4J configuration
log4j.rootLogger=INFO, CONSOLE, FILE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.logger.org.hibernate =WARN

log4j.appender.FILE=org.apache.log4j.rolling.RollingFileAppender 
log4j.appender.FILE.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy 
log4j.appender.FILE.rollingPolicy.maxIndex=2 
log4j.appender.FILE.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 
#log4j.appender.FILE.triggeringPolicy.MaxFileSize=5000000
log4j.appender.FILE.triggeringPolicy.MaxFileSize=50000
log4j.appender.FILE.rollingPolicy.FileNamePattern=D:/Error-%i.log 
log4j.appender.FILE.rollingPolicy.ActiveFileName=D:/Error.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 
log4j.appender.FILE.layout.ConversionPattern=%d %-5p - %c %x %m%n


Application context info log

INFO    2017-03-17 16:34:58,417 [main] org.springframework.context.support.ClassPathXmlApplicationContext  - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@74650e52: startup date [Fri Mar 17 16:34:58 IST 2017]; root of context hierarchy
INFO    2017-03-17 16:34:58,505 [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [rtpapp-config.xml]
INFO    2017-03-17 16:34:58,769 [main] org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions from class path resource [common-config.xml]
INFO    2017-03-17 16:35:00,739 [main] org.springframework.context.support.PropertySourcesPlaceholderConfigurer  - Loading properties file from class path resource [mq-config.properties]
INFO    2017-03-17 16:35:00,741 [main] org.springframework.context.support.PropertySourcesPlaceholderConfigurer  - Loading properties file from class path resource [digisignature.properties]
INFO    2017-03-17 16:35:00,751 [main] org.springframework.context.support.PropertySourcesPlaceholderConfigurer  - Loading properties file from class path resource [mq-config.properties]
INFO    2017-03-17 16:35:00,886 [main] org.springframework.cache.ehcache.EhCacheManagerFactoryBean  - Initializing EhCache CacheManager
INFO    2017-03-17 16:35:03,050 [main] org.springframework.oxm.jaxb.Jaxb2Marshaller  - Creating JAXBContext by scanning packages [com.cfts.rtp.messages]
INFO    2017-03-17 16:35:05,980 [main] com.mchange.v2.log.MLog  - MLog clients using log4j logging.
INFO    2017-03-17 16:35:06,014 [main] com.mchange.v2.c3p0.C3P0Registry  - Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
INFO    2017-03-17 16:35:08,903 [main] org.springframework.context.support.DefaultLifecycleProcessor  - Starting beans in phase 2147483647
INFO    2017-03-17 16:35:09,375 [main] org.springframework.jms.connection.SingleConnectionFactory  - Established shared JMS Connection: com.ibm.mq.jms.MQQueueConnection@19b75b2b
INFO    2017-03-17 16:35:09,580 [main] org.springframework.jms.connection.SingleConnectionFactory  - Established shared JMS Connection: com.ibm.mq.jms.MQQueueConnection@79195c22


Solution : I found solution like to add 2 properties file(commons-logging.properties and simplelog.properties) in class path.

commons-logging.properties


org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

simplelog.properties


org.apache.commons.logging.simplelog.defaultlog=warn


Related Post: 

Stepwise how to implement spring logging with log4j
How to turning off hibernate logging console output

No comments:

Post a Comment