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)