Introduction to Java Logging

1、Slf4j

The full name of slf4j is Simple Logging Facade For Java, that is, it is just a unified interface that provides log output for Java programs, not a specific log implementation scheme, just like JDBC, it is just a rule. Therefore, slf4j alone cannot work, and must be matched with other specific log implementation solutions, such as apache's org.apache.log4j.Logger, jdk's own java.util.logging.Logger, etc.

2、Log4j

Log4j is an open source project of Apache. By using Log4j, we can control the destination of log information transmission to be the console, file, GUI component, or even socket server, NT event recorder, UNIX Syslog daemon, etc.; we also The output format of each log can be controlled; by defining the level of each log information, we can control the log generation process in more detail.
Log4j consists of three important components: loggers (Loggers), output terminals (Appenders) and log formatters (Layout).

  • Logger: Control which logging statements to enable or disable, and limit the level of log information
  • Appenders : Specifies whether the log will be printed to the console or to a file
  • Layout : Control the display format of log information

The Log information to be output in Log4j defines 5 levels, which are DEBUG, INFO, WARN, ERROR and FATAL in turn. When outputting, only the information whose level is higher than the level specified in the configuration can be really output, which is very convenient. to configure what to output in different situations without changing the code.

3、LogBack

Simply put, Logback is a logging framework in the Java world. It is considered the successor of Log4J.
Logback is mainly composed of three modules: logback-core, logback-classic. logback-access
logback-core is the infrastructure for other modules, and other modules are built on it. Obviously, logback-core provides some key common mechanisms.
The status and role of logback-classic are equivalent to Log4J, it is also considered an improved version of Log4J, and it implements the simple log facade SLF4J; logback-access is mainly used as a
module that interacts with Servlet containers, such as tomcat or jetty, Provide some functions related to HTTP access

4. Advantages of Logback

 The same code path, Logback executes faster
 More adequate testing
 Native implementation of SLF4J API (Log4J also needs an intermediate conversion layer)
 Richer documentation
 Support XML or Groovy configuration
 Automatic hot loading of configuration files 13/04/2018 Page 170 of 283
 Graceful recovery from IO errors
 Automatically delete log archives
 Automatically compress logs into archive files
 Support Prudent mode, so that multiple JVM processes can record the same log file
 Support configuration files Conditional judgment to adapt to different environments
 More powerful filters
 Support SiftingAppender (Appender can be filtered)
 Exception stack information with package information

5、ELK

ELK is the abbreviation of the software collection Elasticsearch, Logstash, and Kibana. These three software and their related components can create a large-scale real-time log processing system.

  • Elasticsearch is a Lucene-based distributed storage and indexing engine that supports full-text indexing. It is mainly responsible for indexing and storing logs to facilitate retrieval and query by business parties.
  • Logstash is a middleware for log collection, filtering, and forwarding. It is mainly responsible for collecting and filtering various logs of various business lines, and forwarding them to Elasticsearch for further processing.
  • Kibana is a visualization tool, which is mainly responsible for querying Elasticsearch data and visually displaying it to the business side, such as various pie charts, histograms, area diagrams, etc.
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_44183847/article/details/129100222