Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

journal: make current log file have a fixed name #7112

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions journal/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,28 @@ func (f *fsJournal) rollJournalFile() error {
if f.fi != nil {
_ = 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),
))

// check if journal file exists
if fi, err := os.Stat(current); err == nil && !fi.IsDir() {
err := os.Rename(current, rolled)
if err != nil {
return xerrors.Errorf("failed to roll journal file: %w", err)
}
}

nfi, err := os.Create(filepath.Join(f.dir, fmt.Sprintf("lotus-journal-%s.ndjson", build.Clock.Now().Format(RFC3339nocolon))))
nfi, err := os.Create(current)
if err != nil {
return xerrors.Errorf("failed to open journal file: %w", err)
return xerrors.Errorf("failed to create journal file: %w", err)
}

f.fi = nfi
f.fSize = 0

return nil
}

Expand Down