c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package log
|
|
|
|
import (
|
|
"io"
|
|
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/util"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/util/rotatingfilewriter"
|
|
)
|
|
|
|
type WriterFileOption struct {
|
|
FileName string
|
|
MaxSize int64
|
|
LogRotate bool
|
|
DailyRotate bool
|
|
MaxDays int
|
|
Compress bool
|
|
CompressionLevel int
|
|
}
|
|
|
|
type eventWriterFile struct {
|
|
*EventWriterBaseImpl
|
|
fileWriter io.WriteCloser
|
|
}
|
|
|
|
var _ EventWriter = (*eventWriterFile)(nil)
|
|
|
|
func NewEventWriterFile(name string, mode WriterMode) EventWriter {
|
|
w := &eventWriterFile{EventWriterBaseImpl: NewEventWriterBase(name, "file", mode)}
|
|
opt := mode.WriterOption.(WriterFileOption)
|
|
var err error
|
|
w.fileWriter, err = rotatingfilewriter.Open(opt.FileName, &rotatingfilewriter.Options{
|
|
Rotate: opt.LogRotate,
|
|
MaximumSize: opt.MaxSize,
|
|
RotateDaily: opt.DailyRotate,
|
|
KeepDays: opt.MaxDays,
|
|
Compress: opt.Compress,
|
|
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 = util.NopCloser{Writer: LoggerToWriter(FallbackErrorf)}
|
|
}
|
|
w.OutputWriteCloser = w.fileWriter
|
|
return w
|
|
}
|
|
|
|
func init() {
|
|
RegisterEventWriter("file", NewEventWriterFile)
|
|
}
|