这是代码: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 关注
- 104 浏览
添加回答
举报
0/150
提交
取消