Learn the Go Language Log pack (Log,logger)

Source: Internet
Author: User

Package Main;import ("Log" "OS" "Time" "FMT") func main () {//Create output log file logfile, err: = OS. Create ("./" + time.) Now (). Format ("20060102") + ". txt"); if err! = Nil {fmt. PRINTLN (err);} Create a logger//parameter 1: Log write destination//Parameter 2: prefix//Parameter 3 for each log: Log attribute Loger: = log. New (LogFile, "Test_", log. Ldate|log. Ltime|log. Lshortfile);//flags returns the output option Fmt.println of logger (Loger. Flags ());//setflags Set output option Loger.setflags (log. Ldate | Log. Ltime | Log. Lshortfile);//returns the output prefix FMT. Println (Loger. Prefix ());//Set output prefix loger. Setprefix ("Test_");//output a log loger. Output (2, "Print a log Message");//Format out log loger. Printf ("Content%d:%s", 11, "I am Wrong");//equivalent to print (); Os.exit (1); Loger. Fatal ("I am Wrong");//equivalent to print ();p anic (); Loger. Panic ("I Was wrong"); the//log export function//export function based on STD,STD is the standard error output//var std = New (OS. Stderr, "", lstdflags)//Get output item FMT. Println (log. Flags ());//Gets the prefix FMT. Printf (log. Prefix ());//output contents log. Output (2, "output content");//format outputs log. Printf ("Content%d:%s", 22, "I was wrong"); log. Fatal ("I Was wrong"); log. Panic ("I Was wrong");}

  

Learn the Go Language Log pack (Log,logger)

Related Article

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.