Apache Solr Logging through Log4j



Bydefault Solr uses slf4j for logging. Follow below mentioned steps to configure Solr with log4j.

  1. First delete slf4j-jdk14-1.5.5.jar file from $CATALINA_HOME/webapps/solr/WEB-INF/lib/slf4j-jdk14-1.5.5.jar location.
  2. Now download slf4j source from http://www.slf4j.org/dist/slf4j-1.5.5.tar.gz and extract it.
  3. Now copy slf4j-log4j12-1.5.5.jar from extracted location to $CATALINA_HOME/webapps/solr/WEB-INF/lib folder.
  4. Now download http://mirrors.dcarsat.com.ar/apache/logging/log4j/1.2.17/log4j-1.2.17.tar.gz and extract it.
  5. Now copy log4j-1.2.17.jar from extracted location to $CATALINA_HOME/webapps/solr/WEB-INF/lib folder.
  6. Now create $CATALINA_HOME/webapps/solr/WEB-INF/classes directory and add file “log4j.properties” with below content.

log4j.rootLogger=ERROR, CONSOLE

log4j.logger.org.apache.solr=INFO

log4j.appender.CONSOLE=org.apache.log4j.RollingFileAppender
log4j.appender.CONSOLE.File=${catalina.base}/logs/catalina.out
log4j.appender.CONSOLE.MaxFileSize=200MB
log4j.appender.CONSOLE.MaxBackupIndex=10
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{DATE} %x %-5p [%c{3}] %m%n

  1. Now rename $CATALINA_HOME/conf/logging.properties file to $CATALINA_HOME/conf/logging.properties.bak.
  2. Now restart tomcat.


Above configuration will keep writing logs in catalina.out file until it reaches 200MB size. Once it cross 200MB it will be renamed with catalina.out.1 and new after that new logs will be written to catalina.out file. MaxBackupIndex parameter will retain those many number of catalina.out files. Once it cross MaxBackupIndex limit, the old file (ex: catalina.out.10) will be removed.  

No comments:

Post a Comment