這是代碼:tmp, _ := os.OpenFile(filepath.Join(this.dirPath , "Log_"+time.Now().Format(conf.FormatFile())), os.O_CREATE|os.O_WRONLY, os.ModePerm)logrus.SetOutput(tmp)它可以工作,但是如果再次運行程序并且已經存在同名文件,則不會寫入它,沒有錯誤,沒有寫入日志,僅此而已。在我看來,這個 os.ModePerm 標志有些東西。該問題僅在linux上重復。
1 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
您可能應該使用os.O_APPEND標志。
tmp, _ := os.OpenFile(
filepath.Join(this.dirPath, "Log_"+time.Now().Format(conf.FormatFile())),
os.O_APPEND|os.O_WRONLY,
os.ModePerm,
)
https://godoc.org/os#pkg-constants
- 1 回答
- 0 關注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消