Skip to content

Optional enforcement of *Context methods #13

Closed
@mattdowdell

Description

@mattdowdell

I came across this on golangci/golangci-lint#4133 and it looks to be very close to some of what I wanted to do myself. Given that you have a good foundation here already, I wondered if you'd be open to an additional optional extra.

Right now, the slog API allows methods like slog.Info and slog.InfoContext. The stdlib doesn't appear to differentiate between these, but a custom handler might take values from the context and add them as fields, e.g. trace/span IDs. What I'd like to be able to enforce is making sure the context is always specified which means disallowing the methods not suffixed with Context.

I suspect this is behaviour that only makes sense with a custom backend, hence the optionality. Is this something you'd be open to?

Another couple of ideas I had that are about consistency and style than API usage:

  • Be able to enforce a format for attribute keys, e.g. kebab-case, snake_case or camelCase, to ensure consistency in aggregated logs and make it easier to group values together the log viewer of choice.
  • Detect and reject uses of fmt.Sprintf when building log messages in favour of putting interpolated values into attributes instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions