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:
Melody Becker 2025-03-24 17:28:38 +01:00
parent afcc54c831
commit 2c285bdde0
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI

View file

@ -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
}