Skip to content

v0.154.0

Choose a tag to compare

@ernado ernado released this 12 Jun 14:53
6ac0462

Highlights

This release replaces the hard dependency on go.uber.org/zap
with the minimal, dependency-free github.com/gotd/log logging
port across all packages. This is a breaking change for any code that sets Logger on
telegram.Options (or any other gotd option struct that exposes a logger).

Why

zap leaked into the core dependency graph of every gotd consumer. gotd/log is a two-method
port (Enabled/Log) with no third-party dependencies; the concrete backend is chosen by the
consumer through a separate adapter module, so the backend's dependency never enters the core
graph. Levels match log/slog and scalar attributes avoid boxing on hot paths.

Migrating your loggers

The Logger fields changed type from *zap.Logger to github.com/gotd/log.Logger. Pick the
migration path that matches the logger you already use.

Keeping zap (smallest change)

Wrap your existing *zap.Logger with the logzap adapter:

import (
	"go.uber.org/zap"
	"github.com/gotd/log/logzap"
	"github.com/gotd/td/telegram"
)

zapLog, _ := zap.NewProduction()

client := telegram.NewClient(appID, appHash, telegram.Options{
	Logger: logzap.New(zapLog), // was: Logger: zapLog
})

Add the adapter module to your build:

go get github.com/gotd/log/logzap@latest

Using the standard library log/slog (no extra deps beyond stdlib)

import (
	"log/slog"
	"github.com/gotd/log/logslog"
	"github.com/gotd/td/telegram"
)

client := telegram.NewClient(appID, appHash, telegram.Options{
	Logger: logslog.New(slog.Default()),
})

Other backends

Drop-in adapter modules ship for the common loggers — import only the one you use, and its
dependency stays out of your core graph:

Backend Adapter module
go.uber.org/zap github.com/gotd/log/logzap
stdlib log/slog github.com/gotd/log/logslog
github.com/rs/zerolog github.com/gotd/log/logzerolog
github.com/sirupsen/logrus github.com/gotd/log/loglogrus

No logger at all

If you previously passed zap.NewNop() (or nothing), no change is required — nil now defaults
to log.Nop, which discards every record. You can also pass log.Nop explicitly:

import "github.com/gotd/log"

telegram.Options{Logger: log.Nop}

Writing your own log call sites

If your application logged through the same *zap.Logger you handed to gotd, you can keep using
zap directly — the migration only affects the value you pass into gotd options. If you want to log
against the gotd/log port itself, use the Helper for ergonomic call sites:

import "github.com/gotd/log"

h := log.For(l) // log.For(nil) is a no-op Helper
h.Info(ctx, "connected", log.String("dc", dc))

What's Changed

  • feat(log): migrate to github.com/gotd/log abstraction by @ernado in #1770

Full Changelog: v0.153.0...v0.154.0