Skip to content

slog.Handler #63

@AlekSi

Description

@AlekSi

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions