fix(logrotate): Now creates dir needed
If the directory containing the target log file doesn't exist, try and create the directory first
This commit is contained in:
parent
afcc54c831
commit
2c285bdde0
1 changed files with 8 additions and 0 deletions
|
@ -4,6 +4,7 @@ package logrotate
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -54,6 +55,13 @@ func (w *RotateWriter) Rotate() (err error) {
|
|||
}
|
||||
|
||||
// Create a file.
|
||||
dir := path.Dir(w.filename)
|
||||
_, err = os.Stat(dir)
|
||||
if err != nil {
|
||||
if err = os.Mkdir(dir, os.ModeDir); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
w.fp, err = os.Create(w.filename)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue