Documentation
¶
Index ¶
- func Debug(msg string, fields ...Fields)
- func DebugOp(op, msg string, fields ...Fields)
- func Error(msg string, err error, fields ...Fields)
- func ErrorOp(op, msg string, err error, fields ...Fields)
- func Info(msg string, fields ...Fields)
- func InfoOp(op, msg string, fields ...Fields)
- func SetDefaultLogger(logger *Logger)
- func Warn(msg string, fields ...Fields)
- func WarnOp(op, msg string, fields ...Fields)
- type Config
- type Entry
- type Fields
- type Level
- type Logger
- func (l *Logger) Debug(msg string, fields ...Fields)
- func (l *Logger) DebugOp(op, msg string, fields ...Fields)
- func (l *Logger) Error(msg string, err error, fields ...Fields)
- func (l *Logger) ErrorOp(op, msg string, err error, fields ...Fields)
- func (l *Logger) Fatal(msg string, err error, fields ...Fields)
- func (l *Logger) GetLevel() Level
- func (l *Logger) Info(msg string, fields ...Fields)
- func (l *Logger) InfoOp(op, msg string, fields ...Fields)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(msg string, fields ...Fields)
- func (l *Logger) WarnOp(op, msg string, fields ...Fields)
- func (l *Logger) WithComponent(component string) *Logger
- func (l *Logger) WithFields(fields Fields) *Logger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger sets the global default logger
Types ¶
type Config ¶
type Config struct {
Level Level
Output io.Writer
Component string
IncludeTrace bool
IncludeFile bool
}
Config holds logger configuration
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a default logger configuration
type Entry ¶
type Entry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
Fields map[string]interface{} `json:"fields,omitempty"`
Component string `json:"component,omitempty"`
Operation string `json:"operation,omitempty"`
Error string `json:"error,omitempty"`
StackTrace string `json:"stack_trace,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
}
Entry represents a single log entry
type Level ¶
type Level int
Level represents the severity level of a log message
func ParseLevel ¶
ParseLevel parses a string into a log level
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the main logging interface
Example ¶
logger := New(&Config{
Level: LevelInfo,
Component: "example",
})
logger.Info("Application started")
logger.InfoOp("database.connect", "Connected to database", Fields{
"host": "localhost",
"port": 5432,
})
logger.Error("Failed to process request", errors.New("connection timeout"))
func (*Logger) WithComponent ¶
WithComponent returns a new logger with the specified component
Example ¶
logger := New(DefaultConfig())
dbLogger := logger.WithComponent("database")
dbLogger.Info("Database initialized")
apiLogger := logger.WithComponent("api")
apiLogger.Info("API server started")
func (*Logger) WithFields ¶
WithFields returns a new logger with the specified default fields
Example ¶
logger := New(DefaultConfig())
requestLogger := logger.WithFields(Fields{
"request_id": "abc123",
"user_id": "user456",
})
requestLogger.Info("Processing request")
requestLogger.Info("Request completed")
Click to show internal directories.
Click to hide internal directories.