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 .... (cherry picked from commit 8d9193680de72dbe32dbad8abce837870d7806e9)
This commit is contained in:
parent
e14d239005
commit
942d02f8e9
1 changed files with 6 additions and 1 deletions
|
@ -4,6 +4,8 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
|
"code.gitea.io/gitea/modules/util/rotatingfilewriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +21,7 @@ type WriterFileOption struct {
|
||||||
|
|
||||||
type eventWriterFile struct {
|
type eventWriterFile struct {
|
||||||
*EventWriterBaseImpl
|
*EventWriterBaseImpl
|
||||||
fileWriter *rotatingfilewriter.RotatingFileWriter
|
fileWriter io.WriteCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ EventWriter = (*eventWriterFile)(nil)
|
var _ EventWriter = (*eventWriterFile)(nil)
|
||||||
|
@ -37,7 +39,10 @@ func NewEventWriterFile(name string, mode WriterMode) EventWriter {
|
||||||
CompressionLevel: opt.CompressionLevel,
|
CompressionLevel: opt.CompressionLevel,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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)
|
FallbackErrorf("unable to open log file %q: %v", opt.FileName, err)
|
||||||
|
w.fileWriter = nopCloser{Writer: LoggerToWriter(FallbackErrorf)}
|
||||||
}
|
}
|
||||||
w.OutputWriteCloser = w.fileWriter
|
w.OutputWriteCloser = w.fileWriter
|
||||||
return w
|
return w
|
||||||
|
|
Loading…
Reference in a new issue