docs: log 日志

This commit is contained in:
Shikong 2021-10-05 22:21:02 +08:00
parent fee0adc3da
commit 11361a4dab

35
base/log/main.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
)
// log
func main() {
logFilePath, _ := filepath.Abs(filepath.Join(os.TempDir(), "./log.log"))
f, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
return
}
defer func() {
_ = f.Close()
}()
// 设置 log 输出位置
// 默认 输出到 标准输出流
//log.SetOutput(os.Stdout)
// 输出 到 指定文件
log.SetOutput(f)
for {
log.Println("测试日志")
time.Sleep(1 * time.Second)
}
}