journal: make current log file have a fixed named (#7112)
This commit is contained in:
parent
7c484cae13
commit
15667db6a9
@ -108,14 +108,28 @@ func (f *fsJournal) rollJournalFile() error {
|
|||||||
if f.fi != nil {
|
if f.fi != nil {
|
||||||
_ = f.fi.Close()
|
_ = f.fi.Close()
|
||||||
}
|
}
|
||||||
|
current := filepath.Join(f.dir, "lotus-journal.ndjson")
|
||||||
|
rolled := filepath.Join(f.dir, fmt.Sprintf(
|
||||||
|
"lotus-journal-%s.ndjson",
|
||||||
|
build.Clock.Now().Format(RFC3339nocolon),
|
||||||
|
))
|
||||||
|
|
||||||
nfi, err := os.Create(filepath.Join(f.dir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(RFC3339nocolon))))
|
// check if journal file exists
|
||||||
|
if fi, err := os.Stat(current); err == nil && !fi.IsDir() {
|
||||||
|
err := os.Rename(current, rolled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to open journal file: %w", err)
|
return xerrors.Errorf("failed to roll journal file: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nfi, err := os.Create(current)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("failed to create journal file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.fi = nfi
|
f.fi = nfi
|
||||||
f.fSize = 0
|
f.fSize = 0
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user