logger

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualLogger

type ContextualLogger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

ContextualLogger provides structured logging with context awareness

func New

func New(serviceName string) *ContextualLogger

New creates a new contextual logger

func (*ContextualLogger) LogBusinessEvent

func (l *ContextualLogger) LogBusinessEvent(ctx context.Context, event string, data map[string]interface{})

Business operation methods

func (*ContextualLogger) LogDatabaseOperation

func (l *ContextualLogger) LogDatabaseOperation(ctx context.Context, query string, duration time.Duration, rowsAffected int64)

func (*ContextualLogger) LogError

func (l *ContextualLogger) LogError(ctx context.Context, err error, message string, data map[string]interface{})

func (*ContextualLogger) LogExternalAPICall

func (l *ContextualLogger) LogExternalAPICall(ctx context.Context, service string, method string, url string, statusCode int, duration time.Duration)

func (*ContextualLogger) LogPerformanceEvent

func (l *ContextualLogger) LogPerformanceEvent(ctx context.Context, operation string, duration time.Duration, data map[string]interface{})

func (*ContextualLogger) LogSecurityEvent

func (l *ContextualLogger) LogSecurityEvent(ctx context.Context, event string, data map[string]interface{})

func (*ContextualLogger) WithContext

func (l *ContextualLogger) WithContext(ctx context.Context) LoggerEntry

WithContext creates a log entry with context information

func (*ContextualLogger) WithCorrelation

func (l *ContextualLogger) WithCorrelation(correlationID string) LoggerEntry

WithCorrelation creates a log entry with correlation ID

func (*ContextualLogger) WithError

func (l *ContextualLogger) WithError(err error) LoggerEntry

WithError creates a log entry with error information

func (*ContextualLogger) WithFields

func (l *ContextualLogger) WithFields(fields map[string]interface{}) LoggerEntry

WithFields creates a log entry with multiple fields

func (*ContextualLogger) WithOperation

func (l *ContextualLogger) WithOperation(operation string) LoggerEntry

WithOperation creates a log entry with operation information

func (*ContextualLogger) WithTenant

func (l *ContextualLogger) WithTenant(tenantID string) LoggerEntry

WithTenant creates a log entry with tenant information

func (*ContextualLogger) WithUser

func (l *ContextualLogger) WithUser(userID string) LoggerEntry

WithUser creates a log entry with user information

type LogEntry

type LogEntry struct {
	*logrus.Entry
}

LogEntry represents a log entry with context

func (*LogEntry) WithContext added in v1.0.1

func (e *LogEntry) WithContext(ctx context.Context) LoggerEntry

Implement LoggerEntry interface methods for LogEntry

func (*LogEntry) WithError added in v1.0.1

func (e *LogEntry) WithError(err error) LoggerEntry

func (*LogEntry) WithField added in v1.0.1

func (e *LogEntry) WithField(key string, value interface{}) LoggerEntry

func (*LogEntry) WithFields added in v1.0.1

func (e *LogEntry) WithFields(fields map[string]interface{}) LoggerEntry

type Logger

type Logger interface {
	// Context-aware logging
	WithContext(ctx context.Context) LoggerEntry
	WithTenant(tenantID string) LoggerEntry
	WithUser(userID string) LoggerEntry
	WithCorrelation(correlationID string) LoggerEntry
	WithOperation(operation string) LoggerEntry
	WithFields(fields map[string]interface{}) LoggerEntry
	WithError(err error) LoggerEntry

	// Business event logging
	LogBusinessEvent(ctx context.Context, event string, data map[string]interface{})
	LogSecurityEvent(ctx context.Context, event string, data map[string]interface{})
	LogPerformanceEvent(ctx context.Context, operation string, duration time.Duration, data map[string]interface{})
	LogError(ctx context.Context, err error, message string, data map[string]interface{})
	LogDatabaseOperation(ctx context.Context, query string, duration time.Duration, rowsAffected int64)
	LogExternalAPICall(ctx context.Context, service string, method string, url string, statusCode int, duration time.Duration)
}

Logger defines the interface for contextual logging

func NewLogger

func NewLogger(serviceName string) Logger

Factory function

type LoggerEntry

type LoggerEntry interface {
	// Standard logging levels
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	// Formatted logging
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	// Context and field manipulation
	WithContext(ctx context.Context) LoggerEntry
	WithField(key string, value interface{}) LoggerEntry
	WithFields(fields map[string]interface{}) LoggerEntry
	WithError(err error) LoggerEntry
}

LoggerEntry defines the interface for a log entry

Jump to

Keyboard shortcuts

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