You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2013/04/29 21:38:10 UTC

[Solr Wiki] Update of "SolrLogging" by ShawnHeisey

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "SolrLogging" page has been changed by ShawnHeisey:
http://wiki.apache.org/solr/SolrLogging?action=diff&rev1=24&rev2=25

Comment:
Initial update for Solr 4.3

  <<TableOfContents>>
  
  = Solr's Logging Mechanism =
+ 
+ Starting with Solr 1.4, the Solr Code base compiles against the "SLF4J" API.
+ 
- == Solr 1.4 and Above ==
+ == Solr 4.3 and above ==
- Starting with Solr 1.4, the Solr Code base compiles against the "SLF4J" API and provides a runtime jar (slf4j-jdk14-X.Y.Z.jar) that implements SLF4J using JDK standard logging -- so all of the information listed below regarding Solr 1.3 and configuring JDK standard logging still applies by default.
  
- Users who want an alternate logging implementation (log4j, logback etc) will need to repackage the .war file and replace slf4j-jdk14-X.Y.Z.jar with an alternate implementation.
+ These versions do not include any logging jars in the WAR file.  They must be provided separately.  The Solr example for these versions includes jars (in the jetty lib/ext directory) that set up SLF4J with a binding to the Apache log4j library.  By changing the jar files, you can easily switch to an alternate logging mechanism (like logback) or use upgraded versions of the logging components.
+ 
+ == Solr 1.4 to 4.2.1 ==
+ These versions include SLF4J jars in the WAR File that set up to use JDK standard logging (JUL, the java.util.logging classes).  An overview of how JUL can be configured at the JVM level can be found here:
+ 
+ http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html
+ 
+ Many servlet containers also provide alternate log configuration options in their configuration files.  You should consult your servlet container documentation to see what options are available.
+ 
+ The Solr Admin console has a [[http://localhost:8983/solr/admin/logging.jsp|screen for toggling the logging level globally]].  This is a transient setting good for doing diagnostic work, but does not persist after restart.
+ 
+ Users who want an alternate logging implementation (log4j, logback etc) will need to repackage the .war file to remove the existing SLF4J jar files and replace them with the [[http://www.slf4j.org/manual.html|correct jar files]].  You can do this by extracting and repacking the .war file, or by building the war file from source without the jar files.
  
  <!> From [[Solr3.6]] there is a build target {{{ant dist-war-excl-slf4j}}} which will automatically package the WAR file with only the slf4j-api JAR and no bindings. Using this war file you can place your slf4j-XXX.jar binding file of choice in your servlet container external lib folder.  Note that the slf4j jar(s) that you add must match the version number of the slf4j-api jar file that is contained within the war.  For Solr 3.6, that version is 1.6.1.  For Solr 4.0, it is 1.6.4.
  
- <!> From [[Solr4.1]] there are two build targets related to choosing your own slf4j binding.  These are {{{ant dist-excl-slf4j}}} and {{{ant dist-war-excl-slf4j}}}.  The first target builds the usual dist files in addition to the WAR file, the second just builds the WAR file.  These build targets will package the WAR without any slf4j jars at all, so you must include all relevant slf4j jars in your container external lib directory.
+ <!> From [[Solr4.1]] there are two build targets related to choosing your own slf4j binding.  These are {{{ant dist-excl-slf4j}}} and {{{ant dist-war-excl-slf4j}}}.  The first target builds the usual dist files in addition to the WAR file, the second just builds the WAR file.  These build targets will package the WAR without any slf4j jars at all, so you must include all relevant slf4j jars in your container external lib directory.  These build targets were removed from [[Solr4.3]] and later.
  
- Here are the slf4j jars that are in the WAR file when you build it without one of the special targets mentioned above:
+ Here are the slf4j jars that are in the WAR file when you build it without one of the special targets:
  
   * slf4j-api-1.6.1.jar
   * slf4j-jdk14-1.6.1.jar
   * jcl-over-slf4j-1.6.1.jar
   * log4j-over-slf4j-1.6.1.jar
  
- The first file is the primary slf4j library.  The second is the binding that slf4j uses to send logs to java.util.logging.  Some of Solr's dependent components use other logging methods - jcl and log4j.  The remaining jar files above intercept calls to these other logging methods and inject them into slf4j.
+ The first file is the primary slf4j library.  The second is the slf4j binding - in this case .  Some of Solr's dependent components use other logging methods - jcl and log4j.  The remaining jar files above intercept calls to these other logging methods and inject them into slf4j.
  
  When you change the slf4j binding, you must include the primary library (the -api jar), the binding for the logging method that you wish to use, the jar(s) for that logging method, and relevant "-over-slf4j" jars.  Note that if you choose either jcl or log4j for your binding, you must leave out the matching "-over-slf4j" jar.
  
  More Info: http://www.slf4j.org/
  
  == Solr 1.0 to 1.3 ==
+ These versions use JDK standard logging directly, not through SLF4J.
- Solr uses JDK standard logging, (ie; the java.util.logging.* package; also known as "JUL"), an overview of how that can be configured at the JVM level can be found here...
- 
- http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html
- 
- ...but many servlet containers provide alternate log configuration options in their configuration files.  You should consult your servlet containers documentation to see what options are available.
- 
- The Solr Admin console has a [[http://localhost:8983/solr/admin/logging.jsp|screen for toggling the logging level globally]].  This is a transient setting good for doing diagnostic work, but does not persist after reboot.
  
  = Customizing Logging =
  == With Example Jetty Instance ==
  If you don't know much about JDK containers or servlet containers and want a quick recipe for modifying the logging settings for default Solr example/ setup, see LoggingInDefaultJettySetup.
  
- == Using log4j with the Solr 4.1 source distribution ==
- Currently Solr 4.1 is not available for easy download because it has not been released yet, so you must obtain a [[NightlyBuilds|nightly version]] or [[HowToContribute#Getting_the_source_code|get it from svn]].  Once it's downloaded, extract it, cd to the solr directory in the extracted directory, then compile it using {{{ant dist-war-excl-slf4j}}} as mentioned in the Solr 4.1 note in the first section above.
+ == Using log4j with Solr from source, 4.2.1 or earlier ==
+ Prior to [[Solr4.3]], using a different SLF4J binding (such as log4j) meant either repackaging the war file or building it yourself from source.   To build it yourself, you need to obtain a [[NightlyBuilds|nightly version]] or [[HowToContribute#Getting_the_source_code|get it from svn]].  Once it's downloaded, extract it, cd to the solr directory in the extracted directory, then compile it using {{{ant dist-war-excl-slf4j}}} or {{{and dist-excl-slf4j}}} depending on the version.
  
  Here are the jars you will need to put in your container external lib folder, assuming that you get the 1.7 version of slf4j.  The last one comes from the log4j website, not slf4j:
  
@@ -48, +55 @@

   * jcl-over-slf4j-1.7.5.jar
   * log4j-1.2.17.jar
  
- http://www.slf4j.org/download.html http://logging.apache.org/log4j/1.2/
+ http://www.slf4j.org/download.html
+ http://logging.apache.org/log4j/1.2/
  
  Note that log4j must be configured before it will work. One way to do this is to pass an argument like the following to java:
  
  {{{
  -Dlog4j.configuration=file:etc/log4j.properties
- 
  }}}
+ 
  http://logging.apache.org/log4j/1.2/manual.html#defaultInit
  
  Sample log4j.properties file:
@@ -82, +90 @@

  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  
  log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n
- 
  }}}
+ 
  == Using Logback with the Solr 3.5 binary distribution ==
- Here are some details for implementing logback (http://logback.qos.ch/). As you may know, Logback is from the same author as Log4j. It has several enhancements including Filters and Custom Appenders.
+ Here are some details for implementing logback (http://logback.qos.ch/). As you may know, Logback was created by the original author of Log4j. It has several enhancements including Filters and Custom Appenders.
  
  1. Get Solr 3.5 http://www.apache.org/dyn/closer.cgi/lucene/solr/3.5.0 and extract the tar/zip file on your system.
  
@@ -95, +103 @@

  # cd $ORIG
  
  # tar xzvf apache-solr-3.5.0.tgz
- 
  }}}
+ 
  2. Copy the solr.war file to a new location
  
  {{{
@@ -111, +119 @@

  # jar xvf solr.war
  
  # rm -f solr.war
- 
  }}}
+ 
  3. Remove the slf4j-jdk14-1.6.1.jar file
  
  {{{
  # cd /tmp/solr
  
  # rm -f ./WEB-INF/lib/slf4j-jdk14-1.6.1.jar
- 
  }}}
+ 
  4. Copy logback classic files
  
  Get the file: http://logback.qos.ch/dist/logback-1.0.1.tar.gz
@@ -133, +141 @@

  # cp logback-classic-1.0.1.jar /tmp/solr/WEB-INF/lib
  
  # cp logback-core-1.0.1.jar /tmp/solr/WEB-INF/lib
- 
  }}}
+ 
  Note: If you wanted to upgrade SLF4J from 1.6.1 to 1.6.4 you would do the following...
  
  a. Get the SLF4J from http://www.slf4j.org/dist/slf4j-1.6.4.tar.gz <<BR>> b. Extract the tar into a temporary directory <<BR>> c. delete the old versions: <<BR>>
@@ -145, +153 @@

  # rm /tmp/solr/WEB-INF/lib/log4j-over-slf4j-1.6.1.jar
  
  # rm /tmp/solr/WEB-INF/lib/slf4j-api-1.6.1.jar
- 
  }}}
+ 
  d. Copy the new ones <<BR>>
  
  {{{
@@ -155, +163 @@

  # cp log4j-over-slf4j-1.6.4.jar /tmp/solr/WEB-INF/lib
  
  # cp slf4j-api-1.6.4.jar /tmp/solr/WEB-INF/lib
- 
  }}}
+ 
  5. Rebuild the war
  
  {{{
  # cd /tmp/solr
  
  # jar cvf solr.war *
- 
  }}}
+ 
  6. Copy the war back to your example/webapps directory
  
  {{{
  # cp solr.war $ORIG/apache-solr-3.5.0/example/webapps
- 
  }}}
+ 
  7. Create resources/logback.xml file
  
  {{{
  # cd $ORIG/apache-solr-3.5.0/example
  
  # mkdir resources
- 
  }}}
+ 
  copy logback.xml into this directory.
  
  8. Restart Solr 3.5
@@ -241, +249 @@

    </root>
  
  </configuration>
- 
  }}}