logging

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCallerInfo

func GetCallerInfo(skip int) (string, int, string)

func WithEnvironment

func WithEnvironment(environment string) func(*Config)

WithEnvironment creates a config option to set the environment

func WithService

func WithService(serviceName string) func(*Config)

WithService creates a config option to set the service name

func WithVersion

func WithVersion(version string) func(*Config)

WithVersion creates a config option to set the service version

Types

type Config

type Config struct {
	Level LogLevel `json:"level"`

	Format string `json:"format"` // "json" or "text"

	ServiceName string `json:"service_name"`

	Version string `json:"version"`

	Environment string `json:"environment"`

	Component string `json:"component"`

	AddSource bool `json:"add_source"`

	TimeFormat string `json:"time_format"`
}

func DefaultConfig

func DefaultConfig(serviceName, version, environment string) Config

type LogLevel

type LogLevel string
const (
	LevelDebug LogLevel = "debug"

	LevelInfo LogLevel = "info"

	LevelWarn LogLevel = "warn"

	LevelError LogLevel = "error"
)

type RequestContext

type RequestContext struct {
	RequestID string

	UserID string

	TraceID string

	SpanID string

	Method string

	Path string

	IP string

	UserAgent string
}

type StructuredLogger

type StructuredLogger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(serviceName, level string) *StructuredLogger

func NewStructuredLogger

func NewStructuredLogger(config Config) *StructuredLogger

func NewStructuredLoggerWithOptions

func NewStructuredLoggerWithOptions(options ...func(*Config)) *StructuredLogger

NewStructuredLogger creates a new structured logger with functional options

func (*StructuredLogger) DebugWithContext

func (sl *StructuredLogger) DebugWithContext(msg string, args ...any)

func (*StructuredLogger) ErrorWithContext

func (sl *StructuredLogger) ErrorWithContext(msg string, err error, args ...any)

func (*StructuredLogger) InfoWithContext

func (sl *StructuredLogger) InfoWithContext(msg string, args ...any)

func (*StructuredLogger) LogAPIUsage

func (sl *StructuredLogger) LogAPIUsage(endpoint, method, userID string, requestSize, responseSize int64, duration time.Duration)

func (*StructuredLogger) LogAuditEvent

func (sl *StructuredLogger) LogAuditEvent(action, resource, userID string, metadata map[string]interface{})

func (*StructuredLogger) LogBusinessEvent

func (sl *StructuredLogger) LogBusinessEvent(eventType string, metadata map[string]interface{})

func (*StructuredLogger) LogFormat

func (sl *StructuredLogger) LogFormat(level LogLevel, msg string, obj interface{})

func (*StructuredLogger) LogHTTPRequest

func (sl *StructuredLogger) LogHTTPRequest(method, path string, statusCode int, duration time.Duration, size int64)

func (*StructuredLogger) LogOperation

func (sl *StructuredLogger) LogOperation(operationName string, fn func() error) error

func (*StructuredLogger) LogPerformance

func (sl *StructuredLogger) LogPerformance(operationName string, duration time.Duration, metadata map[string]interface{})

func (*StructuredLogger) LogResourceUsage

func (sl *StructuredLogger) LogResourceUsage(cpuPercent, memoryMB, diskUsagePercent float64)

func (*StructuredLogger) LogSecurityEvent

func (sl *StructuredLogger) LogSecurityEvent(eventType, description, severity string, metadata map[string]interface{})

func (*StructuredLogger) LogSystemMetrics

func (sl *StructuredLogger) LogSystemMetrics(metrics map[string]interface{})

func (*StructuredLogger) WarnWithContext

func (sl *StructuredLogger) WarnWithContext(msg string, args ...any)

func (*StructuredLogger) WithComponent

func (sl *StructuredLogger) WithComponent(component string) *StructuredLogger

func (*StructuredLogger) WithRequest

func (sl *StructuredLogger) WithRequest(ctx *RequestContext) *StructuredLogger

Jump to

Keyboard shortcuts

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