Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 1a36150950432897706b8940120efbe4 > files > 45

logback-1.0.9-2.fc18.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Logback FAQ</title>
    <link rel="stylesheet" type="text/css" href="css/common.css" />
    <link rel="stylesheet" type="text/css" href="css/screen.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="css/_print.css" media="print" />

  </head>
  <body>
    <script type="text/javascript">prefix='';</script>

    <script src="templates/header.js" type="text/javascript"></script>
    <div id="left">
      <script src="templates/left.js" type="text/javascript"></script>
    </div>
    <div id="content">
	
    <h2>
      <a name="top">Frequently Asked Questions</a>
    </h2>
      
    <h3>Logback project</h3>

    <ol>
      <li><a href="#why_lgpl">Why is logback distributed under LGPL
      and not the Apache Software License?</a> </li>

      <li><a href="#dependecy">What are logback's dependencies, i.e.
      JDK version and third-party libraries?</a>
      </li>
    </ol>
  
                      
    <h3>Logback Classic</h3>
    
    
    <ol type="1">    
      <li>
        <a href="#logger_serialization">Are logback loggers
        serializable?</a>
      </li>  
      
      <li>
        <a href="#auto_config">How does the automatic configuration
        work?</a>
      </li>  

      <li>
        <a href="#configFileLocation">Where should the configuration
        files such as <em>logback.groovy</em>,
        <em>logback-test.xml</em> or <em>logback.xml</em> be located
        on the classpath?</a> </li>

      <li>
        <a href="#sharedConfiguration">Is it possible for multiple JEE
        applications to share the same configuration file but without
        stepping on each other's toes?
        </a>
      </li>

      <li>
        <a href="#overrideFromCL">
          How can I disable logging from the command line?            
        </a>
      </li>

      <li>
        <a href="#setup_jetty">How can Jetty be instructed to use
        logback-classic as its logging implementation?
        </a>
      </li>
    </ol>
    
    <!-- =============================================================== -->
    <!-- =============================================================== -->
    <!-- =============================================================== -->
    <!-- =============================================================== -->
  
        
    <div class="section">
      <h2>Logback project</h2>
      
      <dl>
        <dt>
          <a name="why_lgpl" href="#why_lgpl">Why is logback
          distributed under LGPL and not the Apache Software License
          (ASL)?</a> </dt>
        
        <dd>
          <p>The logback project is dual licensed under the LGPL and
          the EPL for two main reasons. For one, the different
          license emphasizes that the fact that logback is a related
          but <em>different</em> project than log4j. 
          </p>

          <p>Both the LGPL and EPL are reasonable and widely-accepted
          licenses. In contrast to the ASL, both the LGPL and he EPL
          require that derivate work be licensed under the same
          license. While there might be debate about the exact
          definition of derivative work, we find such reciprocity both
          justified and morally appealing -- that is the second
          reason for our choice of the LGPL &amp; EPL
          dual-license. The subtly more liberal approach embodied in
          the ASL is not necessarily wrong. It is the expression of a
          different balance.
          </p>
          
        </dd>
      </dl>

      <hr/>

      <dl>
        <dt><a name="dependecy" href="#dependecy">What are logback's
        dependencies, i.e.  JDK version and third-party libraries?</a>
        </dt>

        <dd><p>This question is answered on a <a
        href="dependencies.html">separate page</a> dedicated to the
        question of dependencies.</p>
        </dd>
      </dl>


    </div>
    
    <div class="section">
      <h2>Logback-classic</h2>
      <dl>
        
        <!-- ========================================================= -->
        
        <dt>
          <a name="auto_config" href="#auto_config">
            How does the automatic configuration work?
          </a>
        </dt>
        <dd>
          <p>This question is answered in the <a
          href="manual/configuration.html#auto_configuration">relevant
          section</a> of the logback manual.
          </p>        
          <hr/>
        </dd>
        

        <!-- ========================================================= -->

        <dt>

          <a name="configFileLocation"
          href="#configFileLocation">Where should the configuration
          files such as <em>logback.groovy</em>,
          <em>logback-test.xml</em> or <em>logback.xml</em> be located
          on the classpath?</a>
        </dt>


        <dd>
          <p>Configuration files such as <em>logback.groovy</em>,
          <em>logback-test.xml</em> or <em>logback.xml</em> can be
          located <b>directly</b> under any folder declared in the
          class path. For example, if the class path reads
          "c:/java/jdk15/lib/rt.jar;c:/mylibs/" then the
          <em>logback.xml</em> file should be located directly under
          "c:/mylibs/", that is as "c:/mylibs/logback.xml". Placing it
          under a sub-folder of c:/mylibs/, say, c:/mylibs/other/,
          will not work.</p>
        
          <p>For web-applications, configuration files can be placed
          <b>directly</b> under <em>WEB-INF/classes/</em>.</p>

          <hr/>
        
        </dd>
        
        <!-- ========================================================= -->
        
        <dt>
          <a name="logger_serialization" href="#logger_serialization">
          Are logback loggers serializable?</a>
        </dt>
        <dd>
          <p>Yes. A logback logger <em>is</em> an SLF4J logger and SLF4J
          loggers are serializable. This means that an object
          referencing a logger will be able to log after its
          deserialization.
          </p>
          
          <p>The deserialized logger instance will be generated by
          <code>org.slf4j.LoggerFactory</code>.  Thus, it is possible
          for a logback logger to be deserialized as a log4j or j.u.l.
          logger, depending on the deserialization environment.</p>

          <hr/>
        </dd>
        

        <!-- ========================================================= -->
   
        <dt>
          <a name="sharedConfiguration" href="#sharedConfiguration">
          Is it possible for multiple JEE applications to share the
          same configuration file but without stepping on each other's
          toes?</a>
        </dt>
        <dd>
          <p>Yes, it is. Using <a
          href="manual/configuration.html#variableSubstitution">variable
          substitution</a>, it is possible to have a single
          configuration file to output logs to different destinations
          for each JEE application. Here is a sample
          configuration file designed for this purpose.</p>
          
          <p class="source">&lt;configuration>
  &lt;appender name="FILE" class="ch.qos.logback.core.FileAppender">
    &lt;!-- "application-name" is a variable --&gt;
    &lt;File><b>c:/logs/${application-name}.log</b>&lt;/File>
    &lt;layout class="ch.qos.logback.classic.PatternLayout">
      &lt;Pattern>%d %p %t %c - %m%n&lt;/Pattern>
    &lt;/layout>
  &lt;/appender>
  &lt;root level="debug">
    &lt;appender-ref ref="FILE"/>
  &lt;/root>
&lt;/configuration> </p>

          <p>Assuming each JEE application loads a different copy of
          logback classes into memory, if we can somehow inject a
          different value for <code><em>application-name</em></code>
          each time an application starts, logs will be output to
          different files. We just need to initialize logback with the
          above configuration file while injecting a different value
          for <code><em>application-name</em></code> variable. Here is
          sample code that programmatically configures logback. It
          should be invoked during the initialization of your JEE
          applications.
          </p>

          <p class="source">  LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
  JoranConfigurator jc = new JoranConfigurator();
  jc.setContext(context);
  context.reset(); // override default configuration
  // inject the name of the current application as "application-name"
  // property of the LoggerContext
  <b>context.putProperty("application-name", NAME_OF_CURRENT_APPLICATION);</b>
  jc.doConfigure("/path/to/the/above/configuration/file.xml"); </p>

          <hr/>
        </dd>
        

        <!-- ========================================================= -->

        <dt>
          <a name="overrideFromCL" href="#overrideFromCL">
            How can I disable logging from the command line?
          </a>
        </dt>
        <dd>
          <p>Logback does not allow logging to be disabled from the command
          line. However, if the configuration file allows it, you can
          set the level of loggers on the command line via a Java
          system property. Here is such a configuration file.</p>

          <p class="source">&lt;configuration>
  &lt;appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    &lt;layout class="ch.qos.logback.classic.PatternLayout">
      &lt;Pattern>%d [%thread] %level %logger - %m%n&lt;/Pattern>
    &lt;/layout>
  &lt;/appender>
  &lt;root level="<b>${root-level:-INFO}</b>">
    &lt;appender-ref ref="CONSOLE"/>
  &lt;/root>
&lt;/configuration></p>


          <p>Making use of <a
          href="manual/configuration.html#variableSubstitution">variable
          substitution</a> as well as <a
          href="manual/configuration.html#defaultValuesForVariables">default
          values for variables</a>, if the <span
          class="variable">root-level</span> system property is set to
          <code>OFF</code>, then all logging will be turned
          off. However, if it is not set, it will assume the default
          value of <code>INFO</code>.  Note that you can set the <span
          class="variable">root-level</span> system property to any
          level value of your choice. The value <code>OFF</code> is
          just an example.

          </p>
          <hr/>
        </dd>


        <!-- ========================================================= -->
        
        <dt>
          <a name="setup_jetty"  href="#">
            How can Jetty be instructed to use logback-classic as its
            logging implementataion?
          </a>
        </dt>
        
        <dd>
          <p>The Jetty application server uses SLF4J for its internal
          logging.
          </p>
          
          <p>Logback jar files must be present on Jetty's class
          path. These files are
          <em>logback-core-1.0.9.jar</em> and
          <em>logback-classic-1.0.9.jar</em>. These files
          should be placed under the <em>$JETTY_HOME/lib</em>
          directory.
          </p>

          
          <p>Since Jetty uses an older version of SLF4J internally,
          we recommend that the old version be replaced by
          <em>slf4j-api-1.7.2.jar</em>. This file can be
          downloaded from the <a
          href="http://www.slf4j.org/download.html">SLF4J</a> project.
          </p>
        
          
          <p>For automatically configuring logback-classic, you can
          place the file <em>logback.xml</em> under the
          <em>$JETTY_HOME/resources</em> directory. You can find
          sample configuration files in the
          <em>logback-examples/src/main/java/chapters/appenders/conf/</em>
          folder shipping within the logback distribution.
          </p>

          <hr/>                    
        </dd>
        

        
        
        <!-- end of definitions -->
      </dl>
      
      
    </div>

  <script src="templates/footer.js" type="text/javascript"></script>
  
</div>
  

	

</body>
</html>