# Logback : Explanation & architecture

In 
Published 2022-12-03

This tutorial explains to you what a Logback is and its architecture. This is a Logback overview.

A large application (but not only) includes its own logging mechanism (implemented by a logging framework). We need to log information about the application we run, the state of some instances and all the time we need to log errors and some exceptions. These logs generally are divided into the following groups:

  • SEVERE (HIGHEST LEVEL) - sometimes we have ERROR
  • WARNING
  • INFO
  • CONFIG
  • FINE
  • FINER
  • FINEST (LOWEST LEVEL)

In most of the cases we have two extra options: ALL and OFF. ALL causes the Logger to log all messages, while OFF disables logging.

We don't have to write a logging mechanism because there some, and we can use/ extend them: LOG4J, Logback, tinilog, etc. These frameworks provide the objects, methods and a configuration files necessary to transmit log messages. Java provides a default framework in the java.util.logging package (JUL).

Logback is a generic, reliable, fast and flexible logging library for Java.

Here is the architecture overview of Logback framework:

Here are some good things to know regarding the Logback architecture:

  • The Logback Logger object is responsible for capturing logging information
  • Each Logger is independently configurable
  • The Logback Appender object is responsible for writing (publishing) logging information to various destinations such as a files, databases, JMS, console, UNIX Syslog, etc.
  • A Logger can send log messages to multiple Appenders
  • The Logback Layout Object is used to format logging information (we can get "one-line-at-a-time", XML, HTML, JSON and other formats)

In Logback framework there are 5 normal levels of logger:

  • TRACE : The most detailed logging details
  • DEBUG : Most useful to debug an application.
  • INFO : It provides informational messages.
  • WARN : It provides that application may have harmful events.
  • ERROR : It provides that application having error events

We can also use:

  • OFF : To disable logging in Java
  • ALL : All the messages are logged

Logback's basic architecture is sufficiently generic so as to apply under different circumstances. At the present time, Logback contains three modules: logback-core, logback-classic and logback-access. The core module lays the groundwork for the other two modules. The classic module extends core. The classic module corresponds to a significantly improved version of log4j. The third module called access integrates with Servlet containers to provide HTTP-access log functionality.

Logback-classic natively implements the SLF4J API so that you can readily switch back and forth between logback and other logging systems such as log4j or java.util.logging (JUL) introduced in JDK 1.4.