This article brings you a detailed introduction to the relationship between Java log components. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Overview
This article does not evaluate the pros and cons of the log components, but only compares the relationships. There are several such relationships among the components in the log. A clear understanding of these relationships will help us introduce and use the log.
The log facade refers to the log components that are directly introduced into our program to record logs. These components as the log facade will be used in the program There are several common log facade components listed in the figure above. For example, some software directly uses some components by default. For example, Spring uses commons-logging, and Activiti uses slf4j as the log facade. Other software will also choose the log facade that they think is useful.
In addition to log4j being both a facade and an implementation, both commons-logging and slf4j can print logs directly, and both need to rely on a log implementation to print logs. The above Several log implementations are also shown in the figure.
slf4j does some bridging processing with logback by default, so what is the role of bridging? If I want to use slf4j as the implementation facade, but at the same time I want to Use log4j as the real log implementation. At this time, you need the slf4j-logrj12 jar package. Now you should be able to understand the bridging method.
The purpose here is to avoid some conflicts. For example, in this scenario, we use spring for development, and the software we develop uses slf4j as Log facade. At this time, because Spirng uses commons-logging as the log facade by default, some conflicts will occur at this time, so we can introduce jcl-over-slf4j to overwrite commons-logging through this component. In order to integrate historical software Internal dependencies are overwritten, and dependencies can be changed in this way.
The above is the detailed content of Detailed introduction to the relationship between Java log components. For more information, please follow other related articles on the PHP Chinese website!