mirror of
https://github.com/caddyserver/caddy.git
synced 2026-01-17 01:30:34 +00:00
logging: set file mode when the file already exist (#6391)
101d3e7 introduced a configuration option to set the log file mode.
This option was not taken into account if the file already exists,
making users having to delete their logs to have new logs created
with the right mode.
This commit is contained in:
@@ -167,8 +167,18 @@ func (fw FileWriter) OpenWriter() (io.WriteCloser, error) {
|
||||
fw.RollKeepDays = 90
|
||||
}
|
||||
|
||||
f_tmp, _ := os.OpenFile(fw.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(fw.Mode))
|
||||
// create the file if it does not exist with the right mode.
|
||||
// lumberjack will reuse the file mode across log rotation.
|
||||
f_tmp, err := os.OpenFile(fw.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(fw.Mode))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f_tmp.Close()
|
||||
// ensure already existing files have the right mode,
|
||||
// since OpenFile will not set the mode in such case.
|
||||
if err = os.Chmod(fw.Filename, os.FileMode(fw.Mode)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &lumberjack.Logger{
|
||||
Filename: fw.Filename,
|
||||
|
||||
Reference in New Issue
Block a user