logger

package
v1.12.9 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelInfo  = log.LevelInfo
	LevelWarn  = log.LevelWarn
	LevelError = log.LevelError
	LevelFatal = log.LevelFatal
	LevelDebug = log.LevelDebug
)
View Source
const (
	FormatAuto   = log.FormatAuto
	FormatPretty = log.FormatPretty
	FormatJSON   = log.FormatJSON
)

Variables

View Source
var (
	LoggerFromContext    = log.LoggerFromContext
	WithRequestID        = log.WithRequestID
	RequestIDFromContext = log.RequestIDFromContext
	WithTraceID          = log.WithTraceID
	TraceIDFromContext   = log.TraceIDFromContext
	WithSpanID           = log.WithSpanID
	SpanIDFromContext    = log.SpanIDFromContext
	WithUserID           = log.WithUserID
	UserIDFromContext    = log.UserIDFromContext
)
View Source
var (
	Track              = log.Track
	TrackWithLogger    = log.TrackWithLogger
	TrackWithFields    = log.TrackWithFields
	LogPanic           = log.LogPanic
	LogPanicWithFields = log.LogPanicWithFields
)

Re-export utility functions.

View Source
var (
	// String creates a string field.
	String = log.String
	// Int creates an int field.
	Int = log.Int
	// Int8 creates an int8 field.
	Int8 = log.Int8
	// Int16 creates an int16 field.
	Int16 = log.Int16
	// Int32 creates an int32 field.
	Int32 = log.Int32
	// Int64 creates an int64 field.
	Int64 = log.Int64
	// Uint creates a uint field.
	Uint = log.Uint
	// Uint8 creates a uint8 field.
	Uint8 = log.Uint8
	// Uint16 creates a uint16 field.
	Uint16 = log.Uint16
	// Uint32 creates a uint32 field.
	Uint32 = log.Uint32
	// Uint64 creates a uint64 field.
	Uint64 = log.Uint64
	// Float32 creates a float32 field.
	Float32 = log.Float32
	// Float64 creates a float64 field.
	Float64 = log.Float64
	// Bool creates a bool field.
	Bool = log.Bool

	// Time creates a time field.
	Time = log.Time
	// Duration creates a duration field.
	Duration = log.Duration

	// Error creates an error field.
	Error = log.Error

	// Stringer creates a field from a Stringer.
	Stringer = log.Stringer

	Any       = log.Any
	Namespace = log.Namespace

	Binary = log.Binary

	ByteString = log.ByteString

	Reflect = log.Reflect

	Complex64 = log.Complex64

	Complex128 = log.Complex128

	Stack = log.Stack

	Strings = log.Strings
)

Field constructors that return wrapped fields.

View Source
var (
	// HTTPMethod creates an HTTP method field.
	HTTPMethod = log.HTTPMethod

	// HTTPStatus creates an HTTP status field.
	HTTPStatus = log.HTTPStatus

	// HTTPPath creates an HTTP path field.
	HTTPPath = log.HTTPPath

	// HTTPURL creates an HTTP URL field.
	HTTPURL = log.HTTPURL

	// HTTPUserAgent creates an HTTP user agent field.
	HTTPUserAgent = log.HTTPUserAgent

	// DatabaseQuery creates a database query field.
	DatabaseQuery = log.DatabaseQuery

	// DatabaseTable creates a database table field.
	DatabaseTable = log.DatabaseTable

	// DatabaseRows creates a database rows affected field.
	DatabaseRows = log.DatabaseRows

	// ServiceName creates a service name field.
	ServiceName = log.ServiceName

	// ServiceVersion creates a service version field.
	ServiceVersion = log.ServiceVersion

	// ServiceEnvironment creates a service environment field.
	ServiceEnvironment = log.ServiceEnvironment

	// LatencyMs creates a latency milliseconds field.
	LatencyMs = log.LatencyMs

	MemoryUsage = log.MemoryUsage

	// Custom field constructors.
	Custom = log.Custom

	Lazy = log.Lazy

	// Conditional field - only adds field if condition is true.
	Conditional = log.Conditional

	// Nullable field - only adds field if value is not nil.
	Nullable = log.Nullable
)

Utility field constructors.

View Source
var (
	// RequestID creates a request ID field.
	RequestID = log.RequestID

	// TraceID creates a trace ID field.
	TraceID = log.TraceID

	// SpanID creates a span ID field.
	SpanID = log.SpanID

	// UserID creates a user ID field.
	UserID = log.UserID

	// ContextFields creates fields from context.
	ContextFields = log.ContextFields
)

Context-aware field constructors.

View Source
var (
	// HTTPRequestGroup creates a group of HTTP request fields.
	HTTPRequestGroup = func(method, path, userAgent string, status int) *FieldGroup {
		return log.HTTPRequestGroup(
			method,
			path,
			userAgent,
			status,
		)
	}

	// DatabaseQueryGroup creates a group of database query fields.
	DatabaseQueryGroup = func(query, table string, rows int64, duration time.Duration) *FieldGroup {
		return log.DatabaseQueryGroup(
			query,
			table,
			rows,
			duration,
		)
	}

	// ServiceInfoGroup creates a group of service information fields.
	ServiceInfoGroup = func(name, version, environment string) *FieldGroup {
		return log.ServiceInfoGroup(
			name,
			version,
			environment,
		)
	}
)

Predefined field groups.

Functions

func NewTestLogger

func NewTestLogger() log.Logger

func SetGlobalLogger

func SetGlobalLogger(logger Logger)

Types

type Config added in v1.11.0

type Config = log.Config

Config is the full logger construction surface.

type ErrorHandler

type ErrorHandler = log.ErrorHandler

ErrorHandler provides a callback-based error handler with logging.

type Field

type Field = log.Field

Field represents a structured log field.

type FieldGroup

type FieldGroup = log.FieldGroup

FieldGroup represents a group of related fields.

type Format added in v1.11.0

type Format = log.Format

Format selects the output encoder.

type LogEntry

type LogEntry = log.LogEntry

LogEntry represents a log entry.

type LogLevel

type LogLevel = log.LogLevel

type Logger

type Logger = log.Logger

Logger represents the logging interface.

func GetGlobalLogger

func GetGlobalLogger() Logger

func New added in v1.11.0

func New(cfg Config) Logger

New creates a logger from a full Config.

func NewBeautifulLogger deprecated added in v0.3.0

func NewBeautifulLogger(name string) Logger

NewBeautifulLogger creates a logger that picks its format automatically.

Deprecated: use New(Config{Name: name}).

func NewBeautifulLoggerCompact deprecated added in v0.3.0

func NewBeautifulLoggerCompact(name string) Logger

NewBeautifulLoggerCompact creates a logger without caller information.

Deprecated: use New(Config{Name: name}).

func NewBeautifulLoggerJSON deprecated added in v0.3.0

func NewBeautifulLoggerJSON(name string) Logger

NewBeautifulLoggerJSON creates a JSON logger.

Deprecated: use New(Config{Name: name, Format: FormatJSON}).

func NewBeautifulLoggerMinimal deprecated added in v0.3.0

func NewBeautifulLoggerMinimal(name string) Logger

NewBeautifulLoggerMinimal creates a logger without caller information.

Deprecated: use New(Config{Name: name}).

func NewDevelopmentLogger

func NewDevelopmentLogger() Logger

NewDevelopmentLogger creates a pretty logger at debug level.

The Config spelled out here is exactly what go-utils' deprecated NewDevelopmentLogger builds, so the output is unchanged.

func NewLogger

func NewLogger(config LoggingConfig) Logger

NewLogger creates a logger from the configuration-file struct.

func NewNoopLogger

func NewNoopLogger() Logger

NewNoopLogger creates a logger that discards everything.

func NewProductionLogger

func NewProductionLogger() Logger

NewProductionLogger creates a JSON logger.

Mirrors go-utils' deprecated NewProductionLogger field for field.

type LoggingConfig

type LoggingConfig = log.LoggingConfig

LoggingConfig represents logging configuration.

type LoggingWriter

type LoggingWriter = log.LoggingWriter

LoggingWriter is an io.Writer that logs each write.

type PerformanceMonitor

type PerformanceMonitor = log.PerformanceMonitor

PerformanceMonitor helps monitor performance metrics.

type RateLimited added in v1.12.9

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

RateLimited logs a failure that tends to repeat (an export or an upload to a backend that is down) at warn, at most once per interval, with the number of reports it swallowed since.

func NewRateLimited added in v1.12.9

func NewRateLimited(log Logger, msg string, every time.Duration) *RateLimited

NewRateLimited returns a RateLimited that logs msg through log.

func (*RateLimited) Report added in v1.12.9

func (r *RateLimited) Report(detail string)

Report logs detail as the error field, unless the last line went out less than an interval ago.

type StructuredLog

type StructuredLog = log.StructuredLog

StructuredLog provides a fluent interface for structured logging.

type SugarLogger

type SugarLogger = log.SugarLogger

SugarLogger provides a more flexible API.

type TestLogger

type TestLogger = log.TestLogger

TestLogger provides a test logger implementation.

Jump to

Keyboard shortcuts

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