Skip to content

proposal: log/slog: export Source method in Record to support custom handler implementations #70280

Open
@nesty92

Description

Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

Not relevant

What did you do?

Implement a custom handler for the log/slog package. My custom handler requires access to the source location (file and line) of log entries for detailed logging.

What did you see happen?

The source method in slog.Record is not exported, meaning it’s inaccessible to custom handlers. As a result, I had to re-implement logic to retrieve source location information, which led to redundant code and reduced consistency with Go's built-in logging behavior.

What did you expect to see?

Expected an accessible Source method in slog.Record that allows custom handlers to retrieve source location information without re-implementing the existing internal logic. This would simplify the creation of custom handlers and ensure consistent behavior when accessing log entry sources.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions