Draft:Logback

logback. is a Java logging framework. It is the successor of log4j 1.x and is very similar conceptually to log4j 1.x as both frameworks were developed by the same author. Logback provides a flexible logging framework that allows developers to log messages at various levels of severity and route these messages to different destinations, such as console, file, database, etc.

The main difference between log4j 1.x and logback is that logback implements the SLF4J API natively, including support for the fluent API. In addition, logback has a larger battery of tests and more extensive documentation.

It should be noted that compared to log4j 1.x logback internals have been re-written to perform about ten times faster on certain critical execution paths. Not only are logback components faster, they have a smaller memory footprint as well. Compared to log4j 2.x, logback performs significantly better, even in the case of asynchronous logging and using only packages provided by the JDK.

The Spring Boot framework supports logback as its default logging system. Spring boot also support logback-access logging for HTTP-access logs which are distinct from application logs.

Logback ships with a plethora of appenders, i.e. logging destinations, allowing the user to log to the console, to a file and many other destinations. Logs can be output in various user-defined formats as as in JSON. The ability to turn on or off logging for entire sections of code can be highly valuable during problem diagnosis

Documentation
There are dozens of articles and hundreds of stack overflow entries describing logback. Also noteworthy is the logback manual which is quite exhaustive.

Modules
Logback ships with two modules. The logback-classic module which is the equivalent of log4j 1.x. The logback-access module can be integrated with web-container to log HTTP traffic. The logback-core module provides common functionality required by the previous two modules.

As of march 2024 and logback version 1.5.x, logback-access has moved to a separate github repository.

Dependencies
For Maven users, you can declare logback-classic as a dependency in the pom.xml file of your project.

The transitive dependencies logback-core and slf4j-api will pulled in by Maven automatically.

Using logback-classic
Logback-classic is based on logback-core and natively implements the SLF4J API. Logging is initiated by calling the printing methods of a logger instance.

Loggers are obtained by calling the method of  class.

Configuration
Logback offers powerful configuration options which are too numerous to detail here.

However, here is a sample configuration file that logs to the console.

Here is another configuration file telling logback to write to a file and to roll it over or archive it at midnight. Moreover, only 30 days of history are kept with a maximum size of 30 MB. It should be mentioned that in case of I/O failures, logback will recover gracefully. Thus, if a file server fails temporarily, you no longer need to restart your application just to get logging working again.

Logback-tyler
For certain use cases, it is worthwhile to work directly with configuration files written in Java. The logback-tyler project will translate logback.xml file to it's equivalent but written in Java, typically output in a file called TylerConfigurator. The various examples in the logback manual offer a "Tyler" tab allowing you to experiment with logback-tyler configuration files.

Configuration files in Java load faster than their XML counterparts. Moreover, the execution of TylerConfigurator does not require reflection and can be thus more suitable in GraamVM environments.