Terpene

Content deleted Content added
Man thinking (talk | contribs)
No edit summary
Man thinking (talk | contribs)
Submitting using AfC-submit-wizard
Line 1: Line 1:
{{Short description|logback, currently the most popular logging implementation in Java eco-system}}
{{Draft topics|software|computing|technology}}
{{AfC topic|other}}
{{AfC submission|||ts=20221021214011|u=Man thinking|ns=118}}
{{AfC submission|t||ts=20220222153025|u=Alain madak|ns=118|demo=}}
{{AfC submission|t||ts=20220222153025|u=Alain madak|ns=118|demo=}}



Revision as of 21:40, 21 October 2022


According to mvnrepository, logback[1] is the most popular 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]

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. ^ 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