package log

Import Path
	github.com/gotd/log (on go.dev)

Dependency Relation
	imports 5 packages, and imported by 8 packages

Involved Source Files attr.go helper.go Package log defines a minimal, dependency-free logging port for gotd libraries. A library writes structured records to a [Logger] and never logs through a global or imports a concrete logging framework. The consumer chooses the backend by passing an adapter: see the logslog and logzap subpackages for log/slog and go.uber.org/zap. When no logger is supplied, [Nop] discards every record. The attribute model ([Attr], [Value]) stores scalar values without boxing them into an interface, and the [Logger.Enabled] gate lets callers skip building attributes on hot paths when a level is disabled. with.go
Package-Level Type Names (total 10, in which 8 are exported)
/* sort exporteds by: | */
Attr is a key-value pair attached to a log record. Key string Value Value func Any(key string, value any) Attr func Bool(key string, value bool) Attr func Duration(key string, value time.Duration) Attr func Error(err error) Attr func Float64(key string, value float64) Attr func Group(key string, attrs ...Attr) Attr func Int(key string, value int) Attr func Int32(key string, value int32) Attr func Int64(key string, value int64) Attr func NamedError(key string, err error) Attr func String(key, value string) Attr func Stringer(key string, value fmt.Stringer) Attr func Time(key string, value time.Time) Attr func Uint64(key string, value uint64) Attr func Value.Group() []Attr func github.com/gotd/td/crypto.AuthKey.LogAttr() Attr func Group(key string, attrs ...Attr) Attr func With(l Logger, attrs ...Attr) Logger func Helper.Debug(ctx context.Context, msg string, attrs ...Attr) func Helper.Error(ctx context.Context, msg string, attrs ...Attr) func Helper.Info(ctx context.Context, msg string, attrs ...Attr) func Helper.Warn(ctx context.Context, msg string, attrs ...Attr) func Helper.With(attrs ...Attr) Helper func Logger.Log(ctx context.Context, level Level, msg string, attrs ...Attr) func Wither.With(attrs ...Attr) Logger
Helper wraps a Logger with leveled convenience methods for call sites. It is a thin value type; adapters implement Logger, not Helper. Build one with For; the zero Helper logs to Nop. Debug logs at LevelDebug. Enabled reports whether a record at level would be recorded. Error logs at LevelError. Info logs at LevelInfo. Logger returns the underlying Logger, never nil. Named returns a Helper whose logger is tagged with name. See Named. Warn logs at LevelWarn. With returns a Helper whose logger attaches attrs to every record. See With. func For(l Logger) Helper func Helper.Named(name string) Helper func Helper.With(attrs ...Attr) Helper
Kind enumerates the dynamic type stored in a [Value]. func Value.Kind() Kind const KindAny const KindBool const KindDuration const KindError const KindFloat64 const KindGroup const KindInt64 const KindString const KindTime const KindUint64
Level is the severity of a log record. Values match log/slog (Debug=-4, Info=0, Warn=4, Error=8) so adapters convert by casting; this is an interop convenience, the values are defined here. String returns the canonical name of the level. Level : fmt.Stringer func Helper.Enabled(ctx context.Context, level Level) bool func Logger.Enabled(ctx context.Context, level Level) bool func Logger.Log(ctx context.Context, level Level, msg string, attrs ...Attr) const LevelDebug const LevelError const LevelInfo const LevelWarn
Logger is the logging port a library writes structured records to. Implementations must be safe for concurrent use by multiple goroutines. Enabled reports whether a record at level would be recorded. Callers use it to avoid building attributes on hot paths when logging is off. Log records one structured message. The attrs slice and its contents must not be retained after Log returns. func Named(l Logger, name string) Logger func OrNop(l Logger) Logger func With(l Logger, attrs ...Attr) Logger func Helper.Logger() Logger func Namer.Named(name string) Logger func Wither.With(attrs ...Attr) Logger func For(l Logger) Helper func Named(l Logger, name string) Logger func OrNop(l Logger) Logger func With(l Logger, attrs ...Attr) Logger func github.com/gotd/td/exchange.Exchanger.WithLogger(logger Logger) exchange.Exchanger func github.com/gotd/td/tdsync.NewLogGroup(parent context.Context, logger Logger) *tdsync.LogGroup var Nop
Namer is an optional Logger capability: returning a child Logger tagged with a name. Adapters implement it to map onto a native mechanism (e.g. zap.Logger.Named); Named is a no-op for loggers that do not, since the name is advisory. ( Namer) Named(name string) Logger
Value holds an attribute value without boxing scalar kinds into an interface. num carries int64/uint64/float64/bool/duration bits; s carries strings; a carries the boxed value for KindAny, KindTime and KindError. It is modeled on slog.Value but kept deliberately small and explicit. Any returns the value boxed into an interface, regardless of kind. Bool returns the value as bool. Valid for KindBool. Duration returns the value as time.Duration. Valid for KindDuration. Error returns the value as error, or nil. Valid for KindError. Float64 returns the value as float64. Valid for KindFloat64. Group returns the value's child attributes, or nil. Valid for KindGroup. Int64 returns the value as int64. Valid for KindInt64 and KindDuration. Kind returns the value's kind. String renders the value to a string. For KindString it returns the string unchanged, so Value also satisfies fmt.Stringer. Time returns the value as time.Time, or the zero time. Valid for KindTime. Uint64 returns the value as uint64. Valid for KindUint64. Value : fmt.Stringer Value : math/rand/v2.Source
Wither is an optional Logger capability: returning a child Logger with attrs permanently attached to every record. Adapters implement it to map onto a native mechanism (e.g. zap.Logger.With); With falls back to a wrapper for loggers that do not. ( Wither) With(attrs ...Attr) Logger
Package-Level Functions (total 18, all are exported)
Any returns an Attr holding an arbitrary value. Prefer the typed constructors for scalars: Any boxes the value into an interface.
Bool returns a bool Attr.
Duration returns a time.Duration Attr.
Error returns an Attr with the conventional key "error". A nil err is kept as a nil-valued error Attr.
Float64 returns a float64 Attr.
For returns a Helper writing to l, or to Nop if l is nil.
Group returns an Attr whose value is the given child attributes. Adapters render it as a nested object. As a special case, an empty key inlines the children into the parent (like log/slog), matching zap's Inline.
Int returns an int Attr, stored as int64.
Int32 returns an int32 Attr, stored as int64.
Int64 returns an int64 Attr.
Named returns a child Logger tagged with name. It uses the logger's native Named when it implements Namer, otherwise it returns l unchanged (the name is advisory for backends without a naming concept). With an empty name it returns l unchanged.
NamedError returns an error Attr under an explicit key. Unlike Error, which uses the conventional "error" key, this lets callers name the field.
OrNop returns l, or Nop if l is nil. Callers store the result so no log site needs a nil check.
String returns a string Attr.
Stringer returns an Attr holding value.String(). A nil Stringer yields the string "<nil>".
Time returns a time.Time Attr.
Uint64 returns a uint64 Attr.
With returns a child Logger that attaches attrs to every record. It uses the logger's native With when it implements Wither, otherwise it wraps l. With no attrs it returns l unchanged.
Package-Level Variables (only one, which is exported)
Nop is a Logger that discards every record. Its Enabled always returns false.
Package-Level Constants (total 14, all are exported)
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Value kinds.
Severity levels.
Severity levels.
Severity levels.
Severity levels.