FMT vs Log In Golang

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.