diff options
author | Giteabot <teabot@gitea.io> | 2023-07-24 01:58:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-24 05:58:16 +0000 |
commit | 8d9193680de72dbe32dbad8abce837870d7806e9 (patch) | |
tree | fd9ea804fae5dec5c52c10400dbf8e9e3c1749a2 | |
parent | ab4fd9aa1f0fb6363b3da0b42cfce0ea7123db30 (diff) | |
download | gitea-8d9193680de72dbe32dbad8abce837870d7806e9.tar.gz gitea-8d9193680de72dbe32dbad8abce837870d7806e9.zip |
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 ....
-rw-r--r-- | modules/log/event_writer_file.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/log/event_writer_file.go b/modules/log/event_writer_file.go index 4f41b96453..fd73d7d30a 100644 --- a/modules/log/event_writer_file.go +++ b/modules/log/event_writer_file.go @@ -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 |