Skip to content

Use stderr as fallback if the log file can't be opened #26074

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

Merged
merged 5 commits into from
Jul 24, 2023
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
7 changes: 6 additions & 1 deletion modules/log/event_writer_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package log

import (
"io"

"code.gitea.io/gitea/modules/util/rotatingfilewriter"
)

Expand All @@ -19,7 +21,7 @@ type WriterFileOption struct {

type eventWriterFile struct {
*EventWriterBaseImpl
fileWriter *rotatingfilewriter.RotatingFileWriter
fileWriter io.WriteCloser
}

var _ EventWriter = (*eventWriterFile)(nil)
Expand All @@ -37,7 +39,10 @@ func NewEventWriterFile(name string, mode WriterMode) EventWriter {
CompressionLevel: opt.CompressionLevel,
})
if err != nil {
// if the log file can't be opened, what should it do? panic/exit? ignore logs? fallback to stderr?
// it seems that "fallback to stderr" is slightly better than others ....
FallbackErrorf("unable to open log file %q: %v", opt.FileName, err)
w.fileWriter = nopCloser{Writer: LoggerToWriter(FallbackErrorf)}
}
w.OutputWriteCloser = w.fileWriter
return w
Expand Down