Backward compatibility

July 1, 2026

We’ve already discussed when the default log/slog Logger also serves as the default log Logger. But what if you want to send log logs to a log/slog Logger, without using the global defaults?

Introducing NewLogLogger!

func NewLogLogger

func NewLogLogger(h Handler, level Level) *log.Logger

NewLogLogger returns a new log.Logger such that each call to its Output method dispatches a Record to the specified handler. The logger acts as a bridge from the older log API to newer structured logging handlers.

Well that was easy!

Of course one may wonder why you would want this.

I know of two reasons:

  1. You depend on an old library that expects a *log.Logger.
  2. You’re still mid-migration from log to log/slog. Use this as a backward compatibility shim. (Really, a special case of #1)

Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .

Get daily content like this in your inbox!

Subscribe