1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 12:50:55 +00:00

Merge pull request #2683 from jialijelly/master

Provide permission to access old files to everyone
This commit is contained in:
astaxie 2017-07-03 11:23:49 +08:00 committed by GitHub
commit 82586c70e9
2 changed files with 28 additions and 18 deletions

View File

@ -56,6 +56,8 @@ type fileLogWriter struct {
Perm string `json:"perm"`
RotatePerm string `json:"rotateperm"`
fileNameOnly, suffix string // like "project.log", project is fileNameOnly and .log is suffix
}
@ -65,6 +67,7 @@ func newFileWriter() Logger {
Daily: true,
MaxDays: 7,
Rotate: true,
RotatePerm: "0440",
Level: LevelTrace,
Perm: "0660",
}
@ -237,8 +240,12 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error {
// Find the next available number
num := 1
fName := ""
rotatePerm, err := strconv.ParseInt(w.RotatePerm, 8, 64)
if err != nil {
return err
}
_, err := os.Lstat(w.Filename)
_, err = os.Lstat(w.Filename)
if err != nil {
//even if the file is not exist or other ,we should RESTART the logger
goto RESTART_LOGGER
@ -271,8 +278,9 @@ func (w *fileLogWriter) doRotate(logTime time.Time) error {
if err != nil {
goto RESTART_LOGGER
}
err = os.Chmod(fName, os.FileMode(0440))
// re-start logger
err = os.Chmod(fName, os.FileMode(rotatePerm))
RESTART_LOGGER:
startLoggerErr := w.startLogger()

View File

@ -190,6 +190,7 @@ func testFileRotate(t *testing.T, fn1, fn2 string) {
Rotate: true,
Level: LevelTrace,
Perm: "0660",
RotatePerm: "0440",
}
fw.Init(fmt.Sprintf(`{"filename":"%v","maxdays":1}`, fn1))
fw.dailyOpenTime = time.Now().Add(-24 * time.Hour)
@ -213,6 +214,7 @@ func testFileDailyRotate(t *testing.T, fn1, fn2 string) {
Rotate: true,
Level: LevelTrace,
Perm: "0660",
RotatePerm: "0440",
}
fw.Init(fmt.Sprintf(`{"filename":"%v","maxdays":1}`, fn1))
fw.dailyOpenTime = time.Now().Add(-24 * time.Hour)