mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-09 00:30:28 +00:00
refactor(logging): use the logging package in internal (#1302)
Move the log calls in `internal` onto `logging`, and add what the process-wide logger setup and its tests need: `SetTextFormat` with a line filter for secret masking (replacing `report.MaskingFormatter`), `SetReportCaller`, `SetDefault` and `logtest.SetDefault`. After this only the `logging` package imports logrus. Stacked on https://gitea.com/gitea/runner/pulls/1301. Assisted-by: Codet Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1302 Reviewed-by: bircni <[email protected]>
This commit is contained in:
1 parent
76110557ab
commit
4e8037a93b
25 files changed
+308
-246
No files matched your search
@@ -5,14 +5,24 @@ package logging
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var std = New(NewLogrusHandler(logrus.StandardLogger()))
|
||||
var std atomic.Pointer[Logger]
|
||||
|
||||
func init() {
|
||||
std.Store(New(NewLogrusHandler(logrus.StandardLogger())))
|
||||
}
|
||||
|
||||
// Default returns the process-wide Logger.
|
||||
func Default() *Logger { return std }
|
||||
func Default() *Logger { return std.Load() }
|
||||
|
||||
// SetDefault replaces the process-wide Logger, which tests use to capture what the package
|
||||
// functions log. SetLevel, GetLevel, SetOutput and the format functions keep configuring the
|
||||
// initial logrus-backed Logger.
|
||||
func SetDefault(l *Logger) { std.Store(l) }
|
||||
|
||||
// SetLevel sets the minimum level of the process-wide Logger.
|
||||
func SetLevel(level Level) { logrus.SetLevel(toLogrusLevel(level)) }
|
||||
@@ -26,17 +36,17 @@ func SetOutput(w io.Writer) { logrus.SetOutput(w) }
|
||||
// Output returns where the process-wide Logger writes.
|
||||
func Output() io.Writer { return logrus.StandardLogger().Out }
|
||||
|
||||
func Enabled(level Level) bool { return std.Enabled(level) }
|
||||
func Enabled(level Level) bool { return Default().Enabled(level) }
|
||||
|
||||
func With(args ...any) *Logger { return std.With(args...) }
|
||||
func WithError(err error) *Logger { return std.WithError(err) }
|
||||
func Tracef(format string, args ...any) { std.logf(LevelTrace, format, args) }
|
||||
func Debugf(format string, args ...any) { std.logf(LevelDebug, format, args) }
|
||||
func Infof(format string, args ...any) { std.logf(LevelInfo, format, args) }
|
||||
func Warnf(format string, args ...any) { std.logf(LevelWarn, format, args) }
|
||||
func Errorf(format string, args ...any) { std.logf(LevelError, format, args) }
|
||||
func Trace(args ...any) { std.log(LevelTrace, args) }
|
||||
func Debug(args ...any) { std.log(LevelDebug, args) }
|
||||
func Info(args ...any) { std.log(LevelInfo, args) }
|
||||
func Warn(args ...any) { std.log(LevelWarn, args) }
|
||||
func Error(args ...any) { std.log(LevelError, args) }
|
||||
func With(args ...any) *Logger { return Default().With(args...) }
|
||||
func WithError(err error) *Logger { return Default().WithError(err) }
|
||||
func Tracef(format string, args ...any) { Default().logf(LevelTrace, format, args) }
|
||||
func Debugf(format string, args ...any) { Default().logf(LevelDebug, format, args) }
|
||||
func Infof(format string, args ...any) { Default().logf(LevelInfo, format, args) }
|
||||
func Warnf(format string, args ...any) { Default().logf(LevelWarn, format, args) }
|
||||
func Errorf(format string, args ...any) { Default().logf(LevelError, format, args) }
|
||||
func Trace(args ...any) { Default().log(LevelTrace, args) }
|
||||
func Debug(args ...any) { Default().log(LevelDebug, args) }
|
||||
func Info(args ...any) { Default().log(LevelInfo, args) }
|
||||
func Warn(args ...any) { Default().log(LevelWarn, args) }
|
||||
func Error(args ...any) { Default().log(LevelError, args) }
|
||||
Reference in new issue
Block a user