Source code analysis of Golang log package

a writing background

       Recently researched the source code, the source code package of this study is the log package: logpackage; it should be noted that this package is based on golang1.18the version (below this version, the source code is slightly different, which can be ignored);

Two code description


2.1 logThe role of the package

       logpackage, 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

       logIn the package, three series of functions are provided, namely printseries, panicseries and fatalseries; the description is as follows:

insert image description here

       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 logthe package, a log structure is defined:

Guess you like

Origin blog.csdn.net/whq19890827/article/details/127080108