I’m using org.apache.http.client libraries and this has some default logging. I’ve also got log4j set up to handling my general logging and the http client logging.
The issue I have is that I don’t want the http client logging going into the MySQL database.
Here is the properties file for log4j:
#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender
# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern==%d{yyyy MM dd HH:mm:ss} %p %t %c - %m%n
# now map our console appender as a root logger, means all log messages will go to this appender
log4j.rootLogger = DEBUG, debugTrack, DB
log4j.logger.org.apache=DEBUG, debugTrack, DB
log4j.logger.infoLogger=INFO, infoTrack, DB
log4j.logger.org.apache.http=httpcomm
log4j.logger.org.apache.http.wire=httpcomm
log4j.additivity.org.apache=false
log4j.additivity.infoLogger=false
log4j.appender.debugTrack=org.apache.log4j.RollingFileAppender
log4j.appender.debugTrack.Threshold=DEBUG
log4j.appender.debugTrack.File=log//debugTrack.log
log4j.appender.debugTrack.MaxFileSize=2MB
log4j.appender.debugTrack.MaxBackupIndex=2
log4j.appender.debugTrack.layout = org.apache.log4j.PatternLayout
log4j.appender.debugTrack.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %p %t %c - %m%n
log4j.appender.infoTrack=org.apache.log4j.RollingFileAppender
log4j.appender.infoTrack.Threshold=INFO
log4j.appender.infoTrack.File=log//infoTrack.log
log4j.appender.infoTrack.MaxFileSize=2MB
log4j.appender.infoTrack.MaxBackupIndex=2
log4j.appender.infoTrack.layout = org.apache.log4j.PatternLayout
log4j.appender.infoTrack.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %p %t %c - %m%n
log4j.appender.httpcomm=org.apache.log4j.RollingFileAppender
log4j.appender.httpcomm.Threshold=DEBUG
log4j.appender.httpcomm.File=log//HTTPCommunication.log
log4j.appender.httpcomm.MaxFileSize=2MB
log4j.appender.httpcomm.MaxBackupIndex=2
log4j.appender.httpcomm.layout=org.apache.log4j.PatternLayout
log4j.appender.httpcomm.layout.ConversionPattern=%d{yyyy MM dd HH:mm:ss} %p %t %c - %m%n
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DB.URL=jdbc:mysql://server/database
log4j.appender.DB.driver=com.mysql.jdbc.Driver
log4j.appender.DB.user=root
log4j.appender.DB.password=********
log4j.appender.DB.sql=INSERT INTO tbl_logs(logDate,logger,level,message) VALUES('%d{yyyy-MM-dd HH:mm:ss}','%C','%p','%m')
log4j.appender.DB.layout=org.apache.log4j.PatternLayout
There is an info logger and a debug logger that I wish to keep logging to file and to database. I also wish to keep the HTTP client logging to the file but NOT to the Database.
Can someone please point me in the right direction to achieve this?
Many thanks
Nathan
You have set the
additivitytofalsefor the parent package, meaning nothing will propagate from there. To also get this behaviour for thelog4j.logger.org.apache.httppackage, you need to set this too:Also note that there is no need to specify both
log4j.logger.org.apache.httpandlog4j.logger.org.apache.http.wire, the first one should cover both.