ch.qos.logback.ext.spring
Class LogbackConfigurer

java.lang.Object
  extended by ch.qos.logback.ext.spring.LogbackConfigurer

public class LogbackConfigurer
extends Object

Convenience class that features simple methods for custom Log4J configuration.

Only needed for non-default Logback initialization with a custom config location. By default, Logback will simply read its configuration from a "logback.xml" or "logback_test.xml" file in the root of the classpath.

For web environments, the analogous LogbackWebConfigurer class can be found in the web package, reading in its configuration from context-params in web.xml. In a JEE web application, Logback is usually set up via LogbackConfigListener or LogbackConfigServlet, delegating to LogbackWebConfigurer underneath.

Since:
0.1
Author:
Juergen Hoeller, Bryan Turner, Les Hazlewood, Knute Axelson
See Also:
WebLogbackConfigurer, LogbackConfigListener, LogbackConfigServlet

Method Summary
static void initLogging(String location)
          Initialize logback from the given file.
static void setWorkingDirSystemProperty(String key)
          Set the specified system property to the current working directory.
static void shutdownLogging()
          Shut down Logback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initLogging

public static void initLogging(String location)
                        throws FileNotFoundException,
                               ch.qos.logback.core.joran.spi.JoranException
Initialize logback from the given file.

Parameters:
location - the location of the config file: either a "classpath:" location (e.g. "classpath:logback.xml"), an absolute file URL (e.g. "file:C:/logback.xml), or a plain absolute path in the file system (e.g. "C:/logback.xml")
Throws:
FileNotFoundException - if the location specifies an invalid file path
ch.qos.logback.core.joran.spi.JoranException - Thrown

setWorkingDirSystemProperty

public static void setWorkingDirSystemProperty(String key)
Set the specified system property to the current working directory.

This can be used e.g. for test environments, for applications that leverage LogbackWebConfigurer's "webAppRootKey" support in a web environment.

Parameters:
key - system property key to use, as expected in Logback configuration (for example: "demo.root", used as "${demo.root}/WEB-INF/demo.log")
See Also:
WebLogbackConfigurer

shutdownLogging

public static void shutdownLogging()
Shut down Logback.

This isn't strictly necessary, but recommended for shutting down logback in a scenario where the host VM stays alive (for example, when shutting down an application in a J2EE environment).



Copyright © 2014-2015. All Rights Reserved.