This is a creation in Article, where the information may have evolved or changed.
In a real project, be sure to use log or encapsulate a higher-level custom log, instead of using FMT directly for 2 reasons:
(1) The most important point, the log packet is concurrent goroutine security, and the FMT is not, this is particularly important, you can see the following example
Func main () {log. Printf ("%s", "1.1.1.1002") log. Printf ("%s", "AAA") SigTerm: = Syscall. Signal (log). Println (reflect. TypeOf (sigTerm)) fmt. Println ("Hahahahahahahahahaha") fmt. Println ("Ahahahaha")
}
The results will appear:
2015/01/13 02:12:04 1.1.1.1002
Hahahahahahahahahaha
2015/01/13 02:12:04 AAA
Ahahahaha
2015/01/13 02:12:04 Syscall. Signal
2015/01/13 02:13:17 1.1.1.1002
Hahahahahahahahahaha
2015/01/13 02:13:17 AAA
2015/01/13 02:13:17 Syscall. Signal
Ahahahaha
Hahahahahahahahahaha
2015/01/13 02:13:35 1.1.1.1002
Ahahahaha
2015/01/13 02:13:35 AAA
2015/01/13 02:13:35 Syscall. Signal
Various
If you want to ensure concurrency security, log packets
(2) The log packet will print the time information and the FMT will not
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.