mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-08 08:10:30 +00:00
refactor(logging): replace the logrus backend with log/slog (#1304)
Log through `log/slog`, with a console `slog.Handler` that writes the text the runner has always written (sorted `key=value` fields on a plain stream, a colored prefix on a terminal), so nothing changes for users. I compared its output byte for byte with logrus's `TextFormatter` over plain, colored, timestamped and caller cases. Why not `slog.TextHandler`: its output differs from what users and their log parsers see today, and `ReplaceAttr` cannot close the gap. - level is `WARN` where logrus wrote `warning`, and time has milliseconds and no quotes - fields keep call order instead of being sorted - the caller is one `source=` key, where the runner writes `func=` and `file=` (reshaped by `callPrettyfier`), and `ReplaceAttr` returns a single attribute - no colored prefix on a terminal - no hook to rewrite a whole formatted line, which the process-wide secret masking relies on Libraries that log through logrus's global logger (the workflow model, the Docker client) are forwarded to the process-wide logger, so they keep following its level, format and secret masking. This is why logrus stays in `go.mod`. Stacked on https://gitea.com/gitea/runner/pulls/1303. Assisted-by: Codet Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1304 Reviewed-by: bircni <[email protected]>
This commit is contained in:
1 parent
8502663d0e
commit
e0ef637805
13 files changed
+691
-202
No files matched your search
@@ -188,3 +188,10 @@ func TestShouldRetryDeclare(t *testing.T) {
|
||||
require.Equal(t, tc.retry, shouldRetryDeclare(tc.err), tc.err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// A dependency that reconfigures logrus's global logger when it is loaded makes its own log lines
|
||||
// show up twice or not at all, so this fails when upgrading one starts doing that. It does not
|
||||
// cover a dependency that does so later, while running.
|
||||
func TestLogrusBridgeSurvivesDependencies(t *testing.T) {
|
||||
require.True(t, logging.LogrusBridgeIntact())
|
||||
}
|
||||
Reference in new issue
Block a user