donaricano-btn

Configuration-Syntax(1)


1. Configure Appenders

An appender is configured with the <appender> element, which takes two mandatory attributes name and class.

The name attribute specifies the name of the appender whereas the class attribute specifies the fully qualified name of the appender class to instantiate

The <appender> element may contain zero or one <layout> elements, zero or more <encoder> elements and zero or more <filter> elements

<appender> elements may contain any number of elements corresponding to JavaBean properties of the appender class





블로그 이미지

리딩리드

,
donaricano-btn

Configuration-Syntax

As will be demonstrated over and over, the syntax of logback configuration files is extremely flexible. As such, it is not possible to specify the allowed syntax with a DTD file or an XML schema. Nevertheless, the very basic structure of the configuration file can be described as, <configuration> element, containing zero or more <appender> elements, followed by zero or more <logger> elements, followed by at most one <root> element.


1. Case sensitivity of tag names

Since logback version 0.9.17, tag names pertaining to explicit rules are case insensitive.

For example, <logger>, <Logger> and <LOGER> are valid configuration elements and will be interpreted in the same way


2. Configuring loggers, of the <logger> element

A logger is configured using the <logger> element. A <logger> element takes exactly one mandatory name attribute, an optional level attribute, and an optional additivity attribute, admitting the values true or false.


The <logger> element may contain zero or more <appender-ref> element


3. Configuring the root logger, or the <root> element

The <root> element configures the root logger. It supports a single attribute, namely the level attribute.


4. Example - Setting the level of a logger

4_1. logback.xml

4_2. MyAppLog.java and Foo

4_3. Console

- Note that the message of level DEBUG generated by the "Foo" logger has been suppressed


5. Example - Setting the level of multiple loggers

I can configure the levels of as many loggers as I wish

- Note that the level of the root logger is always set to a non-value, DEBUG by default

블로그 이미지

리딩리드

,
donaricano-btn

Configuration-with logback-test.xml or logback.xml

- logback will try to configure itself using the files logback-test.xml or logback.xml if found on the class path


1. Automatic configuration with logback-test.xml or logback.xml

1_1. configration

1_2. java

2. Automatic printing of status messages in case of warning or errors

- If warnings or errors occur during the parsing of the configuration file, logback will automatically print its internal status data on the console.

- In the absence of warnings or errors, if you still wish to inspect logback's internal status, then you can instruct logback to print status data by invoking the print() of the StatusPrinter Class


3. Status data

- Instead of invoking StatusPrinter programmatically from your code,

you can instruct the configuration file to dump status data, even in the absence of errors

- You need to set the debug attribute of the configuration file

- this debug attribute relates only to the status data

3_1. OnConsoleStatusListener

- It will go a long way in helping you diagnose logback issues. As such, enabling logback status data is very highly recommended and should be considered as a recourse of first resort

'Logging > LogBack' 카테고리의 다른 글

[LogBack] 3_4. Configuration-Syntax(1)  (0) 2016.06.14
[LogBack] 3_3. Configuration-Syntax  (0) 2016.06.03
[LogBack] 3_1. Configuration-Automatically  (0) 2016.05.31
[LogBack] 2. Architecture  (0) 2016.05.26
[LogBack] 1. Introduction  (0) 2016.05.25
블로그 이미지

리딩리드

,
donaricano-btn

Configuration_1

LogBack can be configured either programmatically or with a configuration script expressed in XML or Groovy format.

By the way, existing log4j users can convert their log4.properties files to logback.xml using our Properties Translator web-application


Let us begin by discussing the initialization steps that logback follows to try to configure itself]

1) Logback tries to find a file called logback.groovy in the classpath

2) If no such file is found, logback tries to find a file called logback-test.xml in the classpath

3) If no such file is found, it checks for the file logback.xml in the classpath

4) If no such file is found, service-provider loading facility(introduced in JDK 1.6) is used to resolve the implementation of com.qos.logback.classic.spi.Configurator interface by looking up the file META-INF/services/ch.qos.logback.classic.spi.Configurator in the class path.

Its contents should specify the fully qualified class name of the desired Configurator implementation


5) If none of the above succeeds, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console


1. Automatically configuring logback

- The simplest way to configure logback is by letting logback fall back to its default configuration

- logback will default to invoking BasicConfigurator which will set up a minimal configuration.

This minimal configuration consists of a ConsoleAppender attached to the root logger. The output is formatted using a PatternLayoutEncoder set to the pattern


1_1. MyAppLog


1_2. Foo


1_3. console



'Logging > LogBack' 카테고리의 다른 글

[LogBack] 3_3. Configuration-Syntax  (0) 2016.06.03
[LogBack] 3_2. Configuration-with logback-test.xml or logback.xml  (0) 2016.06.02
[LogBack] 2. Architecture  (0) 2016.05.26
[LogBack] 1. Introduction  (0) 2016.05.25
[LogBack] 0. Define  (0) 2016.05.25
블로그 이미지

리딩리드

,