logging

package
v0.0.0-...-012ce59 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel represents logging severity levels Maps to standard syslog levels for consistent interpretation

const (
	LogLevelDebug LogLevel = iota // Detailed debugging information
	LogLevelInfo                  // General information messages
	LogLevelWarn                  // Warning conditions
	LogLevelError                 // Error conditions
	LogLevelFatal                 // Critical errors causing termination
)

type Logger

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

Logger wraps structured logging with OpenTelemetry integration Provides consistent logging interface across application components Automatically correlates logs with distributed traces for observability Time Complexity: O(1) for logging operations Space Complexity: O(1) per log entry

func NewLogger

func NewLogger(service string) *Logger

NewLogger creates structured logger with OpenTelemetry integration Configures JSON output for structured log parsing and correlation Initializes tracer for distributed tracing integration Time Complexity: O(1) - logger initialisation Space Complexity: O(1) - fixed logger structure

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, msg string, attrs ...slog.Attr)

Debug logs debug-level message with context and trace correlation Used for detailed debugging information in development/troubleshooting Automatically includes trace and span IDs when available Time Complexity: O(1) - structured logging with fixed overhead Space Complexity: O(n) where n is message and attribute size

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, msg string, err error, attrs ...slog.Attr)

Error logs error message with context and trace correlation Used for application errors and exception conditions Automatically marks associated span as error for tracing Time Complexity: O(1) - structured logging with fixed overhead Space Complexity: O(n) where n is message and attribute size

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, msg string, err error, attrs ...slog.Attr)

Fatal logs fatal error and terminates application Used for unrecoverable errors requiring immediate shutdown Exits with code 1 after logging for monitoring systems Time Complexity: O(1) - logging followed by termination Space Complexity: O(n) where n is message and attribute size

func (*Logger) HTTPRequestLogger

func (l *Logger) HTTPRequestLogger() func(next http.Handler) http.Handler

HTTPRequestLogger creates middleware for HTTP request logging Logs request details including method, path, status, and duration Integrates with OpenTelemetry for distributed request tracing Time Complexity: O(1) per request Space Complexity: O(1) for request metadata

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, attrs ...slog.Attr)

Info logs informational message with context and trace correlation Used for general application flow and business logic events Standard level for production operational logging Time Complexity: O(1) - structured logging with fixed overhead Space Complexity: O(n) where n is message and attribute size

func (*Logger) StartSpan

func (l *Logger) StartSpan(ctx context.Context, operationName string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan creates new OpenTelemetry span with logging context Provides distributed tracing for request flow and performance monitoring Automatically propagates trace context for downstream services Time Complexity: O(1) - span creation and context propagation Space Complexity: O(1) - span metadata storage

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, attrs ...slog.Attr)

Warn logs warning message with context and trace correlation Used for recoverable errors and unexpected conditions Indicates potential issues requiring attention Time Complexity: O(1) - structured logging with fixed overhead Space Complexity: O(n) where n is message and attribute size

func (*Logger) WithFields

func (l *Logger) WithFields(attrs ...slog.Attr) *Logger

WithFields creates logger with pre-configured attributes Useful for adding consistent context to related log entries Returns new logger instance to avoid modifying original Time Complexity: O(n) where n is number of attributes Space Complexity: O(n) for attribute storage

Jump to

Keyboard shortcuts

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