GO写日志文件
package main import ( "fmt" "log" "os" "time" ) func main() { fileObj, err := os.OpenFile("./log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { fmt.Println("文件打开错误") } log.SetOutput(fileObj) //每隔3S往文件里写日志 for { log.Println("测试") time.Sleep(time.Second * 3) } }
参考:https://www.bilibili.com/video/BV1fz4y1m7Pm?p=81&spm_id_from=pageDriver