Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-27 20:26:09 +01:00

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

Backport #26074 by @wxiaoguang

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 ....
This commit is contained in:
Giteabot 2023-07-24 01:58:16 -04:00 committed by GitHub
parent ab4fd9aa1f
commit 8d9193680d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,8 @@
package log
import (
"io"
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
)
@ -19,7 +21,7 @@ type WriterFileOption struct {
type eventWriterFile struct {
*EventWriterBaseImpl
fileWriter *rotatingfilewriter.RotatingFileWriter
fileWriter io.WriteCloser
}
var _ EventWriter = (*eventWriterFile)(nil)
@ -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