In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to understand log in the Go language standard library. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Introduction of log in Go language Standard Library
1.log
1.1 using Logger
The log package defines the Logger type, which provides methods for formatting the output.
This package also provides a predefined "standard" logger that can be used by calling Print series (Print | Printf | Println), Fatal series (Fatal | Fatalf | fatalln) and Panic series (Panic | Panicf | PanicLn), which is easier to use than creating your own logger object.
For example, we can call the methods mentioned in the landing directly through the log package as shown in the following code. By default, they will make the log information hidden in the terminal interface.
Package mainimport ("log") func main () {log.Println ("this is a very common log.") V: = "very normal" log.Printf ("this is a% s log.\ n", v) log.Fatalln ("this is a log that triggers fatal.") Log.Panicln ("this is a log that triggers panic.") Result: this is a very ordinary log at 21:57:13 on 2020-02-06. This is a very ordinary log at 21:57:13 on 2020-02-06. 21:57:13 on 2020-02-06 this is a log that triggers fatal. Process finished with exit code 1
Logger prints the date and time of each log message, which is output to the system's standard error by default.
The Fatal series functions write log information and then call os.Exit (1).
The Panic series functions panic after the log information is written.
1.2 configure logger
1.2.1 configuration of standard logger
By default, logger only provides the time information of the log, but in many cases, we want more information, such as the file name and line number of the log.
The log standard library provides us with a way to customize these settings.
The Flags function in the log standard library returns the output configuration of the standard logger, while the SetFlags function is used to set the output configuration of the standard logger.
Func Flags () int
Func SetFlags (flag int)
Flag option
The log standard library provides the following flag options, which are a series of defined constants.
Const (
/ / controls the details of the output log information, not the order and format of the output.
/ / the output log will be separated by a colon after each entry: for example, 2009-01-23 01virtual 23virtual 23.123123 / a/b/c/d.go:23: message
Ldate = 1
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.