1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 19:20:59 +00:00

Provide permission to access old log files to everyone

This commit is contained in:
Jia Li Ong 2017-06-01 17:48:48 +08:00
parent cab8458c1c
commit 5a2eea07cb

View File

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