a writing background
Recently researched the source code, the source code package of this study is the log package: log
package; it should be noted that this package is based on golang1.18
the version (below this version, the source code is slightly different, which can be ignored);
Two code description
2.1 log
The role of the package
log
package, which implements a simple log service; by calling the functions provided by the log package, a simple log printing function can be realized.
2.2 Code structure
log
In the package, three series of functions are provided, namely print
series, panic
series and fatal
series; the description is as follows:
Following the analysis of these three functions, we can see that the bottom layer calls the same function Output()
; so in this article, we mainly analyze this function.
Detailed explanation of three codes
3.1 The structure of log
In log
the package, a log structure is defined: