这是代码:
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上重复。