logging

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package logging provides an abstract interface used internally and which can provide interop with various logging packages. uber-go/zap is preferred.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string)

func Debugf

func Debugf(ctx context.Context, msg string, args ...interface{})

func Debugw

func Debugw(ctx context.Context, msg string, fields ...interface{})

func EnsureLogger

func EnsureLogger(ctx context.Context) context.Context

EnsureLogger ensures that a logger is attached to the context. If one is not present, a new development logger is created and attached.

func Error

func Error(ctx context.Context, msg string)

func Errorf

func Errorf(ctx context.Context, msg string, args ...interface{})

func Errorw

func Errorw(ctx context.Context, msg string, fields ...interface{})

func Fatal

func Fatal(ctx context.Context, msg string)

func Fatalf

func Fatalf(ctx context.Context, msg string, args ...interface{})

func Fatalw

func Fatalw(ctx context.Context, msg string, fields ...interface{})

func Info

func Info(ctx context.Context, msg string)

func Infof

func Infof(ctx context.Context, msg string, args ...interface{})

func Infow

func Infow(ctx context.Context, msg string, fields ...interface{})

func Interceptor

func Interceptor() grpc.UnaryServerInterceptor

Interceptor returns a GRPC Logging interceptor configured to log using the prefab logging adapter.

func Panic

func Panic(ctx context.Context, msg string)

func Panicf

func Panicf(ctx context.Context, msg string, args ...interface{})

func Panicw

func Panicw(ctx context.Context, msg string, fields ...interface{})

func Track

func Track(ctx context.Context, field string, value interface{})

Track a field across the lifetime of the context. Unlike GRPC's logging.InjectFields, tracked values will persist back up the call-chain to the logging interceptor. As such, do not use this as a convenience in loops, without creating a new scope using `logging.With(ctx, logger.Named("foo"))`.

func Warn

func Warn(ctx context.Context, msg string)

func Warnf

func Warnf(ctx context.Context, msg string, args ...interface{})

func Warnw

func Warnw(ctx context.Context, msg string, fields ...interface{})

func With

func With(ctx context.Context, logger Logger) context.Context

With attaches a logger to the context.

This can be used to create logging scopes like so:

for _, u := range users {
  ctx := With(ctx, logger.Named(u.ID))
  processUser(ctx, u)
}

Types

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Debugf(msg string, args ...interface{})
	Info(args ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Infof(msg string, args ...interface{})
	Warn(args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Warnf(msg string, args ...interface{})
	Error(args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Errorf(msg string, args ...interface{})
	Panic(args ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Panicf(msg string, args ...interface{})
	Fatal(args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Fatalf(msg string, args ...interface{})

	// Named creates a child logger with the given name.
	Named(name string) Logger

	// With creates a child logger and attaches structured cotnext to it.
	With(field string, value interface{}) Logger
}

Logger provides an abstract logging interface designed around uber-go/zap's sugared logger, but is intended to provide interop with other libraries.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns a scoped logger.

func NewDevLogger

func NewDevLogger() Logger

NewDevLogger returns a zap logger that prints dev friendly output.

func NewProdLogger

func NewProdLogger() Logger

NewProdLogger returns a zap logger that outputs JSON.

type ZapLogger

type ZapLogger struct {
	// contains filtered or unexported fields
}

ZapLogger is a logging adapter for a Zap Sugarded Logger.

func (*ZapLogger) Debug

func (z *ZapLogger) Debug(args ...interface{})

func (*ZapLogger) Debugf

func (z *ZapLogger) Debugf(msg string, args ...interface{})

func (*ZapLogger) Debugw

func (z *ZapLogger) Debugw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Error

func (z *ZapLogger) Error(args ...interface{})

func (*ZapLogger) Errorf

func (z *ZapLogger) Errorf(msg string, args ...interface{})

func (*ZapLogger) Errorw

func (z *ZapLogger) Errorw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Fatal

func (z *ZapLogger) Fatal(args ...interface{})

func (*ZapLogger) Fatalf

func (z *ZapLogger) Fatalf(msg string, args ...interface{})

func (*ZapLogger) Fatalw

func (z *ZapLogger) Fatalw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Info

func (z *ZapLogger) Info(args ...interface{})

func (*ZapLogger) Infof

func (z *ZapLogger) Infof(msg string, args ...interface{})

func (*ZapLogger) Infow

func (z *ZapLogger) Infow(msg string, keysAndValues ...interface{})

func (*ZapLogger) Named

func (z *ZapLogger) Named(name string) Logger

func (*ZapLogger) Panic

func (z *ZapLogger) Panic(args ...interface{})

func (*ZapLogger) Panicf

func (z *ZapLogger) Panicf(msg string, args ...interface{})

func (*ZapLogger) Panicw

func (z *ZapLogger) Panicw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Warn

func (z *ZapLogger) Warn(args ...interface{})

func (*ZapLogger) Warnf

func (z *ZapLogger) Warnf(msg string, args ...interface{})

func (*ZapLogger) Warnw

func (z *ZapLogger) Warnw(msg string, keysAndValues ...interface{})

func (*ZapLogger) With

func (z *ZapLogger) With(field string, value interface{}) Logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL