logging

package
v0.0.0-...-dc8f43e Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(message string)

Package-level convenience functions

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(message string)

func ErrorWithErr

func ErrorWithErr(message string, err error)

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(message string)

func Fatalf

func Fatalf(format string, args ...interface{})

func GetRequestID

func GetRequestID(c *gin.Context) string

GetRequestID extracts request ID from gin context

func GetUserID

func GetUserID(c *gin.Context) string

GetUserID extracts user ID from gin context

func GinLogger

func GinLogger(logger *Logger) gin.HandlerFunc

Gin middleware for request logging

func Info

func Info(message string)

func Infof

func Infof(format string, args ...interface{})

func SetDefaultLogger

func SetDefaultLogger(logger *Logger)

SetDefaultLogger sets the default logger

func Warn

func Warn(message string)

func Warnf

func Warnf(format string, args ...interface{})

Types

type Config

type Config struct {
	Level        LogLevel
	Output       io.Writer
	Component    string
	EnableCaller bool
	TimeFormat   string
}

Config represents logger configuration

type LogEntry

type LogEntry struct {
	Timestamp   time.Time              `json:"timestamp"`
	Level       LogLevel               `json:"level"`
	Message     string                 `json:"message"`
	Fields      map[string]interface{} `json:"fields,omitempty"`
	Caller      string                 `json:"caller,omitempty"`
	RequestID   string                 `json:"request_id,omitempty"`
	UserID      string                 `json:"user_id,omitempty"`
	Component   string                 `json:"component,omitempty"`
	Operation   string                 `json:"operation,omitempty"`
	Duration    *int64                 `json:"duration_ms,omitempty"`
	Error       string                 `json:"error,omitempty"`
	HTTPMethod  string                 `json:"http_method,omitempty"`
	HTTPPath    string                 `json:"http_path,omitempty"`
	HTTPStatus  int                    `json:"http_status,omitempty"`
	HTTPLatency *int64                 `json:"http_latency_ms,omitempty"`
}

LogEntry represents a structured log entry

type LogLevel

type LogLevel int

LogLevel represents the severity level of a log entry

const (
	DebugLevel LogLevel = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the log level

type Logger

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

Logger represents a structured logger

func GetDefaultLogger

func GetDefaultLogger() *Logger

GetDefaultLogger returns the default logger

func NewLogger

func NewLogger(config Config) *Logger

NewLogger creates a new structured logger

func (*Logger) Debug

func (l *Logger) Debug(message string)

Debug logs a debug message

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs a formatted debug message

func (*Logger) Error

func (l *Logger) Error(message string)

Error logs an error message

func (*Logger) ErrorWithErr

func (l *Logger) ErrorWithErr(message string, err error)

ErrorWithErr logs an error message with an error object

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs a formatted error message

func (*Logger) Fatal

func (l *Logger) Fatal(message string)

Fatal logs a fatal message and exits

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf logs a formatted fatal message and exits

func (*Logger) Info

func (l *Logger) Info(message string)

Info logs an info message

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs a formatted info message

func (*Logger) LogOperation

func (l *Logger) LogOperation(operation string, fn func() error) error

LogOperation logs the start and end of an operation with duration

func (*Logger) Warn

func (l *Logger) Warn(message string)

Warn logs a warning message

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf logs a formatted warning message

func (*Logger) WithComponent

func (l *Logger) WithComponent(component string) *Logger

WithComponent sets the component for this logger

func (*Logger) WithField

func (l *Logger) WithField(key string, value interface{}) *Logger

WithField adds a field to the logger context

func (*Logger) WithFields

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

WithFields adds multiple fields to the logger context

Jump to

Keyboard shortcuts

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