Documentation
¶
Index ¶
- func Debug(msg string, fields ...Field)
- func ErrorLog(msg string, fields ...Field)
- func Info(msg string, fields ...Field)
- func SetDefaultLogger(logger Logger)
- func Warn(msg string, fields ...Field)
- type Field
- func Any(key string, value any) Field
- func Bool(key string, value bool) Field
- func Component(name string) Field
- func Count(n int) Field
- func Duration(key string, value time.Duration) Field
- func EdgeID(id uint64) Field
- func Error(err error) Field
- func Float64(key string, value float64) Field
- func Int(key string, value int) Field
- func Int64(key string, value int64) Field
- func Latency(d time.Duration) Field
- func NodeID(id uint64) Field
- func Operation(op string) Field
- func Path(p string) Field
- func String(key, value string) Field
- func Uint64(key string, value uint64) Field
- type JSONLogger
- func (l *JSONLogger) Debug(msg string, fields ...Field)
- func (l *JSONLogger) Error(msg string, fields ...Field)
- func (l *JSONLogger) GetLevel() Level
- func (l *JSONLogger) Info(msg string, fields ...Field)
- func (l *JSONLogger) SetLevel(level Level)
- func (l *JSONLogger) Warn(msg string, fields ...Field)
- func (l *JSONLogger) With(fields ...Field) Logger
- type Level
- type LogEntry
- type Logger
- type NopLogger
- func (NopLogger) Debug(msg string, fields ...Field)
- func (NopLogger) Error(msg string, fields ...Field)
- func (NopLogger) GetLevel() Level
- func (NopLogger) Info(msg string, fields ...Field)
- func (NopLogger) SetLevel(level Level)
- func (NopLogger) Warn(msg string, fields ...Field)
- func (n NopLogger) With(fields ...Field) Logger
- type TimedOperation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorLog ¶
ErrorLog logs an error-level message using the default logger Named ErrorLog to avoid conflict with Error field constructor
func SetDefaultLogger ¶
func SetDefaultLogger(logger Logger)
SetDefaultLogger sets the global default logger
Types ¶
type Field ¶
Field represents a key-value pair for structured logging
type JSONLogger ¶
type JSONLogger struct {
// contains filtered or unexported fields
}
JSONLogger implements Logger with JSON output
func NewDefaultLogger ¶
func NewDefaultLogger() *JSONLogger
NewDefaultLogger creates a logger that writes to stdout at INFO level
func NewJSONLogger ¶
func NewJSONLogger(writer io.Writer, level Level) *JSONLogger
NewJSONLogger creates a new JSON logger
func (*JSONLogger) Debug ¶
func (l *JSONLogger) Debug(msg string, fields ...Field)
Debug logs a debug-level message
func (*JSONLogger) Error ¶
func (l *JSONLogger) Error(msg string, fields ...Field)
Error logs an error-level message
func (*JSONLogger) GetLevel ¶
func (l *JSONLogger) GetLevel() Level
GetLevel returns the current log level
func (*JSONLogger) Info ¶
func (l *JSONLogger) Info(msg string, fields ...Field)
Info logs an info-level message
func (*JSONLogger) SetLevel ¶
func (l *JSONLogger) SetLevel(level Level)
SetLevel sets the minimum log level
func (*JSONLogger) Warn ¶
func (l *JSONLogger) Warn(msg string, fields ...Field)
Warn logs a warning-level message
func (*JSONLogger) With ¶
func (l *JSONLogger) With(fields ...Field) Logger
With creates a child logger with the given fields pre-set
type Level ¶
type Level int
Level represents a log level
const ( // DebugLevel logs are typically voluminous, and are usually disabled in production DebugLevel Level = iota // InfoLevel is the default logging priority InfoLevel // WarnLevel logs are more important than Info, but don't need individual human review WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs ErrorLevel )
type LogEntry ¶
type LogEntry struct {
Time string `json:"time"`
Level string `json:"level"`
Message string `json:"msg"`
Fields map[string]any `json:"fields,omitempty"`
}
LogEntry represents a single log entry in JSON format
type Logger ¶
type Logger interface {
// Debug logs a debug-level message
Debug(msg string, fields ...Field)
// Info logs an info-level message
Info(msg string, fields ...Field)
// Warn logs a warning-level message
Warn(msg string, fields ...Field)
// Error logs an error-level message
Error(msg string, fields ...Field)
// With creates a child logger with the given fields pre-set
With(fields ...Field) Logger
// SetLevel sets the minimum log level
SetLevel(level Level)
// GetLevel returns the current log level
GetLevel() Level
}
Logger is the interface for structured logging
func NewNopLogger ¶
func NewNopLogger() Logger
NewNopLogger creates a logger that discards all output
type NopLogger ¶
type NopLogger struct{}
NopLogger is a logger that does nothing (useful for testing)
type TimedOperation ¶
type TimedOperation struct {
// contains filtered or unexported fields
}
TimedOperation helps measure operation duration
func StartTimer ¶
func StartTimer(logger Logger, msg string, fields ...Field) *TimedOperation
StartTimer begins timing an operation
func (*TimedOperation) End ¶
func (t *TimedOperation) End()
End logs the operation with its duration
func (*TimedOperation) EndError ¶
func (t *TimedOperation) EndError(err error)
EndError logs the operation as an error with its duration
func (*TimedOperation) EndWithLevel ¶
func (t *TimedOperation) EndWithLevel(level Level, msg string)
EndWithLevel logs the operation at the specified level with its duration