package main import ( "log" "os" ) var ( Info *log.Logger Warning *log.Logger Error * log.Logger ) func main(){ logFile,error:=os.OpenFile("./log.log",os.O_CREATE|os.O_WRONLY|os.O_APPEND,0644) if error!=nil { log.Fatalln("打开日志文件失败") } defer logFile.Close() Info = log.New(logFile,"Info:",log.Ldate | log.Ltime | log.Llongfile) Warning = log.New(logFile,"Warning:",log.Ldate | log.Ltime | log.Llongfile) Error = log.New(logFile,"Error:",log.Ldate | log.Ltime | log.Llongfile) Info.Output(1,"这是info") Warning.Output(1,"warning") Error.Output(1,"error") }