logger

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	LoggerFromContext    = log.LoggerFromContext
	WithRequestID        = log.WithRequestID
	RequestIDFromContext = log.RequestIDFromContext
	WithTraceID          = log.WithTraceID
	TraceIDFromContext   = log.TraceIDFromContext
	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

	Object = log.Object

	Array = log.Array

	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

	// 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 FieldMap

func FieldMap(fields []Field) map[string]any

FieldMap creates a map representation of fields for debugging.

func FieldsToZap

func FieldsToZap(fields []Field) []zap.Field

FieldsToZap converts Field interfaces to zap.Field efficiently.

func NewTestLogger

func NewTestLogger() log.Logger

func SetGlobalLogger

func SetGlobalLogger(logger Logger)

func ValidateField

func ValidateField(field Field) error

ValidateField validates a field and returns an error if invalid.

Types

type BeautifulColorScheme added in v0.3.0

type BeautifulColorScheme = log.BeautifulColorScheme

BeautifulColorScheme defines the color palette for beautiful output.

func DefaultBeautifulColorScheme added in v0.3.0

func DefaultBeautifulColorScheme() BeautifulColorScheme

DefaultBeautifulColorScheme provides a modern minimalist color scheme.

type BeautifulLogger added in v0.3.0

type BeautifulLogger = log.BeautifulLogger

BeautifulLogger is a visually appealing alternative logger implementation with CLI-style output, caller information, and configurable formatting.

func NewBeautifulLogger added in v0.3.0

func NewBeautifulLogger(name string) *BeautifulLogger

NewBeautifulLogger creates a new beautiful logger with defaults.

func NewBeautifulLoggerCompact added in v0.3.0

func NewBeautifulLoggerCompact(name string) *BeautifulLogger

NewBeautifulLoggerCompact creates a compact logger optimized for high-frequency logs.

func NewBeautifulLoggerJSON added in v0.3.0

func NewBeautifulLoggerJSON(name string) *BeautifulLogger

NewBeautifulLoggerJSON creates a logger similar to JSON output (caller, fields, timestamp).

func NewBeautifulLoggerMinimal added in v0.3.0

func NewBeautifulLoggerMinimal(name string) *BeautifulLogger

NewBeautifulLoggerMinimal creates an ultra-minimal logger.

type CustomField

type CustomField = log.CustomField

CustomField represents a field with custom key-value pairs.

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.

func MergeFields

func MergeFields(fieldSlices ...[]Field) []Field

MergeFields merges multiple field slices into one.

func SanitizeFields

func SanitizeFields(fields []Field) []Field

SanitizeFields removes nil and invalid fields.

func WrapZapField

func WrapZapField(zapField zap.Field) Field

WrapZapField wraps a zap.Field to implement the Field interface.

func WrapZapFields

func WrapZapFields(zapFields []zap.Field) []Field

WrapZapFields wraps multiple zap.Fields.

type FieldGroup

type FieldGroup = log.FieldGroup

FieldGroup represents a group of related fields.

type FormatConfig added in v0.3.0

type FormatConfig = log.FormatConfig

FormatConfig controls what components are shown in the output.

func DefaultFormatConfig added in v0.3.0

func DefaultFormatConfig() FormatConfig

DefaultFormatConfig provides sensible defaults.

type LazyField

type LazyField = log.LazyField

LazyField represents a field that evaluates its value lazily.

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 NewDevelopmentLogger

func NewDevelopmentLogger() Logger

NewDevelopmentLogger creates a development logger with enhanced colors.

func NewDevelopmentLoggerWithLevel

func NewDevelopmentLoggerWithLevel(level zapcore.Level) Logger

NewDevelopmentLoggerWithLevel creates a development logger with specified level.

func NewLogger

func NewLogger(config LoggingConfig) Logger

NewLogger creates a new logger with the given configuration.

func NewNoopLogger

func NewNoopLogger() Logger

NewNoopLogger creates a logger that does nothing.

func NewProductionLogger

func NewProductionLogger() Logger

NewProductionLogger creates a production logger.

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 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.

type ZapField

type ZapField = log.ZapField

ZapField wraps a zap.Field and implements the Field interface.

Jump to

Keyboard shortcuts

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