Terpene

Content deleted Content added
Jay (talk | contribs)
change after undeletion - rephrase lede
Dummy edit to reset G13 clock after undeletion (rfud-helper)
Line 1: Line 1:
{{AFC submission|d|context|u=Man thinking|ns=118|decliner=Mattdaviesfsic|declinets=20230110055358|ts=20221021214011}} <!-- Do not remove this line! -->
{{AFC submission|d|context|u=Man thinking|ns=118|decliner=Mattdaviesfsic|declinets=20230110055358|ts=20221021214011}} <!-- Do not remove this line! -->


{{Short description|logback, currently the most popular logging implementation in Java eco-system}}
{{Short description|logback, currently the most popular logging implementation in Java eco-system}}

Revision as of 14:46, 11 April 2024

logback[1] is a Java logging framework[2]. It is the successor[3] of log4j 1.x and is very similar conceptually to log4j 1.x as both frameworks were developed by the same person, namely Ceki Gülcü.

The main difference between log4j 1.x and logback is that logback implements the SLF4J API[4] natively. In addition, logback has a larger battery of tests and more extensive documentation.[5] According to mvnrepository, logback the most popular Java logging framework.[2]

Modules

Logback ships with three 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.

Dependencies

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

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.4.4</version>
</dependency>

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

Architecture of 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[6] instance.

logger.debug("Hello world");

Loggers are obtained by calling the getLogger()[7] method of LoggerFactory[8] class.

Logger logger = LoggerFactory.getLogger(HelloWorld.class);

Configuration

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

Here is a sample configuration file that logs to the console.

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="info">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

References

  1. ^ "Logback Home". logback.qos.ch. Retrieved 2022-02-22.
  2. ^ a b Goebelbecker, Eric (2018-05-08). "A Guide To Logback | Baeldung". www.baeldung.com. Retrieved 2022-08-05.
  3. ^ Paraschiv, Eugen (2017-08-07). "Solving Your Logging Problems with Logback". Stackify. Retrieved 2022-08-05.
  4. ^ "SLF4J". www.slf4j.org. Retrieved 2022-08-05.
  5. ^ "Logback Manual". logback.qos.ch. Retrieved 2022-08-05.
  6. ^ "Logger (Logback-Parent 1.3.0-alpha15 API)". logback.qos.ch. Retrieved 2022-08-05.
  7. ^ "LoggerFactory (SLF4J 2.0.0-alpha7 API)". www.slf4j.org. Retrieved 2022-08-05.
  8. ^ "LoggerFactory (SLF4J 2.0.0-alpha7 API)". www.slf4j.org. Retrieved 2022-08-05.

Leave a Reply