This is a creation in Article, where the information may have evolved or changed.
In go, although there is a log module, but the module does not provide a strong function, for example, there is no common level log function, but it is not difficult to implement a log module.
For the level of log, we define the following:
const ( LevelTrace = iota LevelDebug LevelInfo LevelWarn LevelError LevelFatal)
Accordingly, several functions are provided:
In addition, for a log, we may write it to different places, such as may be directly output to stdout, or write a file, or write a socket, when creating a specific logger, we need to specify the corresponding handler, to implement different writing methods.
Handler is defined as follows:
type Handler interface { Write(p []byte) (n int, err error) Close() error}
We can refer to the Python log module to implement several common handler, such as Streamhandler,filehandler,timerotatingfilehandler.
The implementation of the log module is Https://github.com/siddontang/golib/tree/master/log.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.