mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-13 11:23:42 +00:00
refactor(logging): add a logging abstraction and move the job logger onto it (#1295)
Add `act/common/logging`: a printf-style `Logger` on a slog-shaped `Handler`, with a logrus-backed handler as the only backend, plus a `logtest` handler for tests. Move the job logger onto it: `common.Logger` returns `*logging.Logger`, the job log formatters and the `Reporter` hook become handlers, and composite step IDs travel in the context. Logging is tightly coupled to logrus types (hooks, formatters, `Entry.Data`). Going through our own interface first lets the remaining call sites move over with unchanged behavior, and lets the backend be swapped for `log/slog` in one place afterwards. The global process logger and its masking formatter stay on logrus for now. Assisted-by: Codet Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1295 Reviewed-by: bircni <[email protected]>
This commit is contained in:
1 parent
ad9eeb668a
commit
de961b91eb
50 files changed
+1241
-438
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package logging
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
var std = New(NewLogrusHandler(logrus.StandardLogger()))
|
||||
|
||||
// Default returns the process-wide Logger.
|
||||
func Default() *Logger { return std }
|
||||
|
||||
// SetLevel sets the minimum level of the process-wide Logger.
|
||||
func SetLevel(level Level) { logrus.SetLevel(toLogrusLevel(level)) }
|
||||
|
||||
// GetLevel returns the minimum level of the process-wide Logger.
|
||||
func GetLevel() Level { return fromLogrusLevel(logrus.GetLevel()) }
|
||||
|
||||
func Enabled(level Level) bool { return std.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) }
|
||||
Reference in new issue
Block a user