7.
Logback is intended as a successor to the popular log4j project.
Logback is divided into three modules
logback-core
logback-classic
logback-access
logback-core module lays the groundwork for the other two modules.
logback-classic natively implements the SLF4J API
logback-access module integrates with Servlet containers, such as
Tomcat and Jetty
10. Logger Context
It is the logging space which is categorized according to developer-chosen
criteria.
Every single logger is attached to a LoggerContext.
It is responsible for arranging loggers in a tree like hierarchy.
Loggers are named entities which is case-sensitive.
They follow the hierarchical naming rule.
11. Named Hierarchy
A logger is said to be an ancestor of another logger if its name followed by a dot is
prefix of the descendant logger name.
A logger is said to be a parent of a child logger if there are no ancestors between
itself and the descendant logger.
"com.foo" is a parent of the logger named "com.foo.Bar".
"java" is a parent of "java.util" and an ancestor of "java.util.Vector".
12. Root Logger
The root logger resides at the top of the logger hierarchy. It is exceptional in that it is part of
every hierarchy at its inception. Like every logger, it can be retrieved by its name, as follows:
val rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME)
Other methods :
package org.slf4j;
public interface Logger {
// Printing methods:
public void trace(String message);
public void debug(String message);
public void info(String message);
public void warn(String message);
public void error(String message);
}
13. Effective Level
Loggers may be assigned levels
If a given logger is not assigned a level, then it inherits one from its closest
ancestor with an assigned level
The root logger always has an assigned level. By default, this is DEBUG.
The effective level for a given logger L, is equal to the first non-null level in its
hierarchy, starting at L itself and proceeding upwards in the hierarchy
towards the root logger.
14.
15. Basic Selection Rule
A log request of level p issued to a logger having an effective level q, is enabled if p >=
q.
levels order: TRACE < DEBUG < INFO < WARN < ERROR.
16. Configuration
Logback tries to find a file called logback.groovy in the classpath.
If no such file is found, logback tries to find a file called logback-test.xml in the
classpath.
If no such file is found, it checks for the file logback.xml in the classpath..
If neither file is found, logback configures itself automatically using the
BasicConfigurator which will cause logging output to be directed to the console.
21.
Case sensitivity of tag names
Configuring loggers, or the <logger> element
Configuring the root logger, or the <root> element
Configuring Appenders
23. Appenders
Logback delegates the task of writing a logging event to components called
appenders Logback-core
Console Appender
OutputStreamAppender File Appender
Rolling File Appender
Time Based Size based Fixed Window