go-githubactions icon indicating copy to clipboard operation
go-githubactions copied to clipboard

`slog.Handler`

Open AlekSi opened this issue 5 months ago • 0 comments

It would be great to have an adapter between githubactions.Action and slog.Handler. For example:

// SlogHandler returns [slog.Handler] for that Action.
//
// [slog.LevelDebug], [slog.LevelInfo], [slog.LevelWarn], and [slog.LevelError] severity levels
// are mapped to debug, notice, warning, and error messages, respectively.
//
// [slog.SourceKey] attribute is automatically converted to "file" and "line" fields.
func (c *Action) SlogHandler() slog.Handler

The the caller could do something like

h := slog.NewTextHandler(os.Stderr, nil)
if os.Getenv("GITHUB_ACTIONS") == "true" {
  h = githubactions.New().SlogHandler()
}

slog.SetDefault(slog.New(h))

AlekSi avatar Jul 02 '25 16:07 AlekSi