fix numeric notation of permissions

This commit is contained in:
nichtsen 2021-09-01 18:54:49 +08:00
parent d01f2dddcc
commit 8b57b22c20

View File

@ -67,6 +67,8 @@ type fileLogWriter struct {
Perm string `json:"perm"`
DirPerm string `json:"dirperm"`
RotatePerm string `json:"rotateperm"`
fileNameOnly, suffix string // like "project.log", project is fileNameOnly and .log is suffix
@ -86,6 +88,7 @@ func newFileWriter() Logger {
RotatePerm: "0440",
Level: LevelTrace,
Perm: "0660",
DirPerm: "0770",
MaxLines: 10000000,
MaxFiles: 999,
MaxSize: 1 << 28,
@ -217,8 +220,13 @@ func (w *fileLogWriter) createLogFile() (*os.File, error) {
return nil, err
}
dirperm, err := strconv.ParseInt(w.DirPerm, 8, 64)
if err != nil {
return nil, err
}
filepath := path.Dir(w.Filename)
os.MkdirAll(filepath, os.FileMode(perm))
os.MkdirAll(filepath, os.FileMode(dirperm))
fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm))
if err == nil {