Logback

Logback Overview

Logback was designed by Ceki Gülcü, the creator of log4j, with the goal of becoming the successor project to log4j.

Based on 10 years of experience designing robust logging systems, Logback is faster than existing logging systems and uses fewer resources.

Logback also provides unique convenience features that other logging systems do not have.

Currently, Logback is divided into three modules: logback-core, logback-classic, and logback-access.

  • The logback-core module is the foundation for the other two modules.
  • The logback-classic module can absorb the functionality of log4j 1.x in a greatly improved form.
  • The logback-access module integrates with servlet containers such as Tomcat and Jetty and provides HTTP access logging.

Main Features of Logback

The main features are as follows.

  • High speed and reduced memory usage
    • Based on log4j 1.x, certain critical execution paths have been rewritten to run about 10 times faster, while memory usage has also been reduced.
  • Versatility
    • Because logback-classic natively implements the SLF4J API, it is easy to switch between Logback and other logging frameworks such as log4j 1.x or java.util.logging (JUL).
  • Flexibility
    • Logback configuration can be written with scripts expressed in programmatic, XML, or Groovy formats. Existing log4j users can also convert a log4j.properties file to logback.xml by using a web application. In addition, because configuration files support conditional processing, a single configuration file can properly target various environments such as development, test, and production.
  • Extensive filtering features
    • Logback includes more extensive filtering features than those provided by log4j 1.x. For example, only users who are identifying a problem can be set to debug level, while other users continue logging at warning level.

Performance Comparison of Logback, Log4j, and Log4j2

Unit: ops/ms

Threads log4j sync log4j async log4j2 sync log4j2 async Logback 1.3.0 sync Logback 1.3.0 async
1 987.08 745.34 884.33 844.67 2,139.83 1,760.30
2 542.27 716.09 1,220.76 819.40 2,276.77 1,821.36
4 639.86 676.35 1,406.60 770.27 1,836.99 1,799.39
8 633.13 726.21 1,257.63 733.25 1,787.62 1,774.99
16 585.13 693.74 1,211.31 722.34 1,813.09 1,815.10
32 643.85 657.08 1,203.27 704.08 1,782.81 1,751.21
64 576.67 696.21 1,236.37 726.15 1,740.27 1,644.81

Main Logback Functions

The main functions are as follows.

  • Logger: specifies how logs are output
  • Appender: specifies where logs are output
  • Layout: specifies the log output format
  • Filter: filters logs

Libraries That Provide Similar Features to Logback

  • Apache Log4j
  • java.util.logging (JUL)

Logback Logging Levels

Logback provides five standard log levels.

The levels are assumed to be ordered as shown below.

TRACE < DEBUG < INFO < WARN < ERROR

Level Description
TRACE Informational events with very low importance
DEBUG Informational events with low severity
INFO Events that indicate overall progress
WARN Events that indicate potentially harmful situations
ERROR Error events, regardless of whether they are fatal

Logback Operating Environment

The required operating environment is as follows.

  • Server OS

    • Follows the operating environment of the Java Runtime Environment (JRE)
  • Other operating environment details

    • Logback version 1.3.x or later requires Java 9 for builds. However, it can run on Java 8 or later.
    • Logback version 1.2.x requires Java 6.x.

Logback License

  • Logback can be redistributed under the Eclipse Public License v1.0 or the Lesser General Public License version 2.1.

References