Documentation
¶
Index ¶
- func DefaultEctoLogFunc(msg EctoLogMessage)
- type EctoLogFunc
- type EctoLogMessage
- type EctoLogger
- func (l *EctoLogger) Debug(msg string)
- func (l *EctoLogger) DebugContext(ctx context.Context, msg string)
- func (l *EctoLogger) DebugContextf(ctx context.Context, format string, args ...any)
- func (l *EctoLogger) Debugf(format string, args ...any)
- func (l *EctoLogger) Error(msg string)
- func (l *EctoLogger) ErrorContext(ctx context.Context, msg string)
- func (l *EctoLogger) ErrorContextf(ctx context.Context, format string, args ...any)
- func (l *EctoLogger) Errorf(format string, args ...any)
- func (l *EctoLogger) Fatal(msg string)
- func (l *EctoLogger) FatalContext(ctx context.Context, msg string)
- func (l *EctoLogger) FatalContextf(ctx context.Context, format string, args ...any)
- func (l *EctoLogger) Fatalf(format string, args ...any)
- func (l *EctoLogger) Info(msg string)
- func (l *EctoLogger) InfoContext(ctx context.Context, msg string)
- func (l *EctoLogger) InfoContextf(ctx context.Context, format string, args ...any)
- func (l *EctoLogger) Infof(format string, args ...any)
- func (l *EctoLogger) Warn(msg string)
- func (l *EctoLogger) WarnContext(ctx context.Context, msg string)
- func (l *EctoLogger) WarnContextf(ctx context.Context, format string, args ...any)
- func (l *EctoLogger) Warnf(format string, args ...any)
- func (l *EctoLogger) WithContext(ctx context.Context) Logger
- func (l *EctoLogger) WithError(err error) Logger
- func (l *EctoLogger) WithField(key string, value interface{}) Logger
- func (l *EctoLogger) WithFields(fields map[string]interface{}) Logger
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultEctoLogFunc ¶
func DefaultEctoLogFunc(msg EctoLogMessage)
DefaultEctoLogFunc is the default log function. It marshals the log message to JSON and writes it to stdout.
Types ¶
type EctoLogFunc ¶
type EctoLogFunc func(msg EctoLogMessage)
EctoLogFunc is a function type that defines how a log message should be processed.
type EctoLogMessage ¶
type EctoLogMessage struct {
Level string // The log level of the message. One of: debug, info, warn, error, fatal
Message string // The log message
Fields map[string]interface{} // Fields to add to the log message
Ctx context.Context // The context of the log message
Err error // The error to add to the log message
}
EctoLogMessage represents a log message with its associated metadata.
type EctoLogger ¶
type EctoLogger struct {
// contains filtered or unexported fields
}
EctoLogger is the main logger struct that implements the Logger interface.
func (*EctoLogger) Debug ¶
func (l *EctoLogger) Debug(msg string)
Debug logs a message at the Debug level.
func (*EctoLogger) DebugContext ¶
func (l *EctoLogger) DebugContext(ctx context.Context, msg string)
func (*EctoLogger) DebugContextf ¶
func (l *EctoLogger) DebugContextf(ctx context.Context, format string, args ...any)
func (*EctoLogger) Debugf ¶
func (l *EctoLogger) Debugf(format string, args ...any)
func (*EctoLogger) Error ¶
func (l *EctoLogger) Error(msg string)
Error logs a message at the Error level.
func (*EctoLogger) ErrorContext ¶
func (l *EctoLogger) ErrorContext(ctx context.Context, msg string)
func (*EctoLogger) ErrorContextf ¶
func (l *EctoLogger) ErrorContextf(ctx context.Context, format string, args ...any)
func (*EctoLogger) Errorf ¶
func (l *EctoLogger) Errorf(format string, args ...any)
func (*EctoLogger) Fatal ¶
func (l *EctoLogger) Fatal(msg string)
Fatal logs a message at the Fatal level.
func (*EctoLogger) FatalContext ¶
func (l *EctoLogger) FatalContext(ctx context.Context, msg string)
func (*EctoLogger) FatalContextf ¶
func (l *EctoLogger) FatalContextf(ctx context.Context, format string, args ...any)
func (*EctoLogger) Fatalf ¶
func (l *EctoLogger) Fatalf(format string, args ...any)
func (*EctoLogger) Info ¶
func (l *EctoLogger) Info(msg string)
Info logs a message at the Info level.
func (*EctoLogger) InfoContext ¶
func (l *EctoLogger) InfoContext(ctx context.Context, msg string)
func (*EctoLogger) InfoContextf ¶
func (l *EctoLogger) InfoContextf(ctx context.Context, format string, args ...any)
func (*EctoLogger) Infof ¶
func (l *EctoLogger) Infof(format string, args ...any)
func (*EctoLogger) Warn ¶
func (l *EctoLogger) Warn(msg string)
Warn logs a message at the Warn level.
func (*EctoLogger) WarnContext ¶
func (l *EctoLogger) WarnContext(ctx context.Context, msg string)
func (*EctoLogger) WarnContextf ¶
func (l *EctoLogger) WarnContextf(ctx context.Context, format string, args ...any)
func (*EctoLogger) Warnf ¶
func (l *EctoLogger) Warnf(format string, args ...any)
func (*EctoLogger) WithContext ¶
func (l *EctoLogger) WithContext(ctx context.Context) Logger
WithContext returns a new Logger with the given context added to the logging context.
func (*EctoLogger) WithError ¶
func (l *EctoLogger) WithError(err error) Logger
WithError returns a new Logger with the given error added to the logging context.
func (*EctoLogger) WithField ¶
func (l *EctoLogger) WithField(key string, value interface{}) Logger
WithField returns a new Logger with the given key-value pair added to the logging context.
func (*EctoLogger) WithFields ¶
func (l *EctoLogger) WithFields(fields map[string]interface{}) Logger
WithFields returns a new Logger with the given fields added to the logging context.
type Logger ¶
type Logger interface {
// WithFields returns a new Logger with the given fields added to the logging context.
WithFields(fields map[string]interface{}) Logger
// WithField returns a new Logger with the given key-value pair added to the logging context.
WithField(key string, value interface{}) Logger
// WithContext returns a new Logger with the given context added to the logging context.
WithContext(ctx context.Context) Logger
// WithError returns a new Logger with the given error added to the logging context.
WithError(err error) Logger
// Debug logs a message at the Debug level.
Debug(msg string)
// Debugf logs a formatted message at the Debug level.
Debugf(format string, args ...any)
// DebugContext logs a message at the Debug level with the given context.
DebugContext(ctx context.Context, msg string)
// DebugContextf logs a formatted message at the Debug level with the given context.
DebugContextf(ctx context.Context, format string, args ...any)
// Info logs a message at the Info level.
Info(msg string)
// Infof logs a formatted message at the Info level.
Infof(format string, args ...any)
// InfoContext logs a message at the Info level with the given context.
InfoContext(ctx context.Context, msg string)
// InfoContextf logs a formatted message at the Info level with the given context.
InfoContextf(ctx context.Context, format string, args ...any)
// Warn logs a message at the Warn level.
Warn(msg string)
// Warnf logs a formatted message at the Warn level.
Warnf(format string, args ...any)
// WarnContext logs a message at the Warn level with the given context.
WarnContext(ctx context.Context, msg string)
// WarnContextf logs a formatted message at the Warn level with the given context.
WarnContextf(ctx context.Context, format string, args ...any)
// Error logs a message at the Error level.
Error(msg string)
// Errorf logs a formatted message at the Error level.
Errorf(format string, args ...any)
// ErrorContext logs a message at the Error level with the given context.
ErrorContext(ctx context.Context, msg string)
// ErrorContextf logs a formatted message at the Error level with the given context.
ErrorContextf(ctx context.Context, format string, args ...any)
// Fatal logs a message at the Fatal level
Fatal(msg string)
// Fatalf logs a formatted message at the Fatal level
Fatalf(format string, args ...any)
// FatalContext logs a message at the Fatal level with the given context
FatalContext(ctx context.Context, msg string)
// FatalContextf logs a formatted message at the Fatal level with the given context
FatalContextf(ctx context.Context, format string, args ...any)
}
Logger is an interface for logging operations. It provides methods for logging at different levels (Debug, Info, Warn, Error, Fatal) and allows for adding contextual information through fields and context.
While this interface is implemented by ectologger, Go conventions recommend using your own logger interface in your code.
func NewDefaultEctoLogger ¶
func NewDefaultEctoLogger() Logger
NewDefaultEctoLogger returns a new EctoLogger that logs to the default logger
func NewEctoLogger ¶
func NewEctoLogger(logFunc EctoLogFunc) Logger
NewEctoLogger creates a new EctoLogger with the given log function.