1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-01 04:30:55 +00:00

Merge pull request #2003 from GuyCheung/develop

add os.Chmod when create log file
This commit is contained in:
astaxie 2016-08-02 09:57:51 +08:00 committed by GitHub
commit 1a52a34544
2 changed files with 7 additions and 2 deletions

View File

@ -159,6 +159,10 @@ func (w *fileLogWriter) createLogFile() (*os.File, error) {
return nil, err return nil, err
} }
fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm)) fd, err := os.OpenFile(w.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(perm))
if err == nil {
// Make sure file perm is user set perm cause of `os.OpenFile` will obey umask
os.Chmod(w.Filename, os.FileMode(perm))
}
return fd, err return fd, err
} }

View File

@ -26,7 +26,8 @@ import (
func TestFilePerm(t *testing.T) { func TestFilePerm(t *testing.T) {
log := NewLogger(10000) log := NewLogger(10000)
log.SetLogger("file", `{"filename":"test.log", "perm": "0600"}`) // use 0666 as test perm cause the default umask is 022
log.SetLogger("file", `{"filename":"test.log", "perm": "0666"}`)
log.Debug("debug") log.Debug("debug")
log.Informational("info") log.Informational("info")
log.Notice("notice") log.Notice("notice")
@ -39,7 +40,7 @@ func TestFilePerm(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if file.Mode() != 0600 { if file.Mode() != 0666 {
t.Fatal("unexpected log file permission") t.Fatal("unexpected log file permission")
} }
os.Remove("test.log") os.Remove("test.log")