logging

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logging provides a unified logging interface

Package logging provides a unified logging interface

Index

Constants

View Source
const (
	// LogEncodingConsole represents console encoding for logs
	LogEncodingConsole = "console"
	// LogEncodingJSON represents JSON encoding for logs
	LogEncodingJSON = "json"
	// EnvironmentDevelopment represents the development environment
	EnvironmentDevelopment = "development"
	// MaxPartsLength represents the maximum number of parts in a log message
	MaxPartsLength = 2
	// FieldPairSize represents the number of elements in a key-value pair
	FieldPairSize = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

Factory creates loggers based on configuration

func NewFactory

func NewFactory(cfg FactoryConfig) *Factory

NewFactory creates a new logger factory with the given configuration

func (*Factory) CreateLogger

func (f *Factory) CreateLogger() (Logger, error)

CreateLogger creates a new logger instance with the application name.

type FactoryConfig added in v0.1.5

type FactoryConfig struct {
	AppName     string
	Version     string
	Environment string
	Fields      map[string]any
	// OutputPaths specifies where to write logs
	OutputPaths []string
	// ErrorOutputPaths specifies where to write error logs
	ErrorOutputPaths []string
}

FactoryConfig holds the configuration for creating a logger factory

type LogLevel added in v0.1.5

type LogLevel string

LogLevel represents the severity of a log message

const (
	// LogLevelDebug represents debug level logging
	LogLevelDebug LogLevel = "debug"
	// LogLevelInfo represents info level logging
	LogLevelInfo LogLevel = "info"
	// LogLevelWarn represents warning level logging
	LogLevelWarn LogLevel = "warn"
	// LogLevelError represents error level logging
	LogLevelError LogLevel = "error"
	// LogLevelFatal represents fatal level logging
	LogLevelFatal LogLevel = "fatal"
)

type Logger

type Logger interface {
	// Basic logging methods
	// Debug is used for detailed information, typically useful only for diagnosing problems
	Debug(msg string, fields ...any)
	// Info is used for general operational entries about what's happening inside the application
	Info(msg string, fields ...any)
	// Warn is used for potentially harmful situations
	Warn(msg string, fields ...any)
	// Error is used for error events that might still allow the application to continue running
	Error(msg string, fields ...any)
	// Fatal is used for very severe error events that will presumably lead the application to abort
	Fatal(msg string, fields ...any)

	// Context methods
	// With adds fields to the logger context
	With(fields ...any) Logger
	// WithComponent adds a component name to the logger context
	WithComponent(component string) Logger
	// WithOperation adds an operation name to the logger context
	WithOperation(operation string) Logger
	// WithRequestID adds a request ID to the logger context
	WithRequestID(requestID string) Logger
	// WithUserID adds a user ID to the logger context (sanitized)
	WithUserID(userID string) Logger
	// WithError adds an error to the logger context
	WithError(err error) Logger
	// WithFields adds multiple fields to the logger context
	WithFields(fields map[string]any) Logger
	// SanitizeField returns a sanitized version of a field value
	SanitizeField(key string, value any) any
}

Logger defines the interface for application logging

Jump to

Keyboard shortcuts

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