package main import ( "fmt" "io" "log" "os" "time" ) var ( Info *log.Logger Error *log.Logger ) func init() { //日志输出文件 file, err := os.OpenFile(fmt.Sprintf("./tomcat8/logs/GWY-%s.log", time.Now().Format("20060102")), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { log.Fatalln("Faild to open error logger file:", err) } //自定义日志格式 Info = log.New(io.MultiWriter(file, os.Stderr), "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) Error = log.New(io.MultiWriter(file, os.Stderr), "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) }