go-githubactions
go-githubactions copied to clipboard
`slog.Handler`
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))