] [Logging framework log4j, log4j2, logback, slf4j and other commonly used logging framework facade

First, in a Java program commonly used logging framework can be divided into two categories:

  1. Abstract facade framework no specific implementation, such as: Commons Logging, SLF4J
  2. Specific implementation of the framework, such as: Log4j, Log4j 2, Logback, Jul

Second, the relationship between the common log frame

  1. Log4j2 with Log4j1 undergone great changes, log4j2 incompatible log4j1
  2. Commons Logging and Slf4j is a log facade (facade pattern is commonly used in software engineering a software design pattern, also known as positive mode, aspect mode. It provides a unified high-level interface subsystem of a set of interfaces, so that the sub the system easier to use). log4j and Logback is the concrete implementation of the log. Can be simply understood as the implementation of the interface with the interface, only need to call attention to the interface without the need for attention to the specific implementation, so that decoupling

  3. The more common use is in combination with a Logback Slf4j used in combination, Commons Logging Log4j used in combination with
  4. Logback must cooperate Slf4j use. Because Logback and Slf4j the same person, it is self-evident compatibility

Third, the log frame facade

  Log facade: a typical application, the facade facade pattern mode, also known as the aspect mode, please refer to my blog design mode of appearance mode, log on the facade framework provides a set of log-related functions without specific interface implementation framework, it calls specific implementation framework for logging. That facade log natural log of compatible implementation framework. Log facade is typical of Commons Logging, SLF4J

  The advantage of using log facade:

  Facade log is a cross between the frame and the specific logging system, and a decoupling system embodied by logging framework facade framework application logs. No matter how logging framework to achieve specific changes will not affect the recording function of the system log, but no need to change the system code, in line with the "open - closed principle."

  Commons Logging:

    Apache Commons Logging is a Java-based logging utilities, programming models and other tools for logging package. It provides an API by other tools, logging implementation and realization of the wrapper

  SLF4J:

    Simple Java log facade (Simple Logging Facade for Java, the SLF4J abbreviation), a programming interface is packaged Logging frame mode implemented in appearance. Logging framework can decide when you want to use software deployment, we are currently the main support Java Logging API, Log4j and logback and other frameworks. Released under the MIT License. SLF4J author is Log4j and Logback author Ceki Gülcü

Fourth, the logging implementation framework

  Jul

    Java Util Logging, since Java1.4 official log realization

  Laog4j

    Apache Log4j is a Java-based logging tool. It is made Ceki Gülcü's first, now it is a project of the Apache Software Foundation

  Log4j2

    Apache Log4j 2 apache is the development of a Log4j upgrade products, and is not compatible Log4j

  Logback

    Logback is a logging framework, Log4j is the same authors, all from the hands of Ceki Gülcü

Fifth, choose Java logging framework

  1. Cost considerations: Logback document free of charge. All documentation is comprehensive Logback provided free of charge, unlike Log4J that provide only a partial free documentation and require the user to buy the paid document
  2. Resource overhead: Commons Logging compared to the higher cost of SLF4J
  3. Performance: Logback compared Log4j, Log4j2 have better performance. Logback claimed: some key operations, such as determining whether a recording operation log statements, its performance has been significantly improved. This operation requires Logback 3 nsec, while in the Log4J 30 nanoseconds is required. LogBack create recorder (Logger) faster speed: 13 ms, 23 ms is required in Log4J. More importantly, it gets existing recorder just 94 nanoseconds, and 2234 nanoseconds Log4J need to reduce the time to 1/23. JUL compared with the performance improvement is significant

Reference: https://blog.csdn.net/xintonghanchuang/article/details/90752323

 

Guess you like

Origin www.cnblogs.com/Y-S-X/p/12142408.html