I’m probably doing this in backwards order, but that’s the order the GoDoc presents it…
Now that we’ve looked at each of the methods of the Handler interface, we come to its general description:
type Handler
A Handler handles log records produced by a Logger.
A typical handler may print log records to standard error, or write them to a file or database, or perhaps augment them with additional attributes and pass them on to another handler.
Any of the Handler’s methods may be called concurrently with itself or with other methods. It is the responsibility of the Handler to manage this concurrency.
Users of the slog package should not invoke Handler methods directly. They should use the methods of Logger instead.
Before implementing your own handler, consult https://go.dev/s/slog-handler-guide.
Three important things to take away from this:
- The handler must handle any concurrency issues, such that it’s safe to call any methods concurrently.
- Don’t call handler methods directly, as a user of the
slogpackage. - RTFM 😂 If you’re going to implement a handler, don’t rely merely on this documentation. Read the handler guide.
I don’t plan to disect the handler guide here. That’s a pretty niche thing, and would be of limited interest to most readers, I expect. But if you disagree, let me know. Maybe I can go into greater detail on handler authoring in a longer-form blog post or something, if it’s interesting to folks.