Documentation
¶
Index ¶
- Constants
- func GetTraceIDFromContext(ctx context.Context) string
- type DefaultLogger
- func (d *DefaultLogger) AddField(key string, value interface{}) Logger
- func (d *DefaultLogger) Debug(ctx context.Context, msg string, args ...Field)
- func (d *DefaultLogger) Error(ctx context.Context, msg string, err error, args ...Field)
- func (d *DefaultLogger) Fatal(ctx context.Context, msg string, err error, args ...Field)
- func (d *DefaultLogger) Info(ctx context.Context, msg string, args ...Field)
- func (d *DefaultLogger) ToContext(ctx context.Context) context.Context
- func (d *DefaultLogger) Warn(ctx context.Context, msg string, args ...Field)
- func (d *DefaultLogger) WithComponent(component string) Logger
- func (d *DefaultLogger) WithFields(fields ...Field) Logger
- func (d *DefaultLogger) WithTraceID(traceID string) Logger
- type Field
- type Logger
Constants ¶
View Source
const ( LoggerContextKey contextKey = "logger" TraceIDKey contextKey = "trace-id" ComponentKey contextKey = "component" )
Variables ¶
This section is empty.
Functions ¶
func GetTraceIDFromContext ¶
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
DefaultLogger is a no-op logger that satisfies the api.Logger interface
func (*DefaultLogger) AddField ¶
func (d *DefaultLogger) AddField(key string, value interface{}) Logger
func (*DefaultLogger) Debug ¶
func (d *DefaultLogger) Debug(ctx context.Context, msg string, args ...Field)
func (*DefaultLogger) Info ¶
func (d *DefaultLogger) Info(ctx context.Context, msg string, args ...Field)
func (*DefaultLogger) ToContext ¶
func (d *DefaultLogger) ToContext(ctx context.Context) context.Context
func (*DefaultLogger) Warn ¶
func (d *DefaultLogger) Warn(ctx context.Context, msg string, args ...Field)
func (*DefaultLogger) WithComponent ¶
func (d *DefaultLogger) WithComponent(component string) Logger
func (*DefaultLogger) WithFields ¶
func (d *DefaultLogger) WithFields(fields ...Field) Logger
func (*DefaultLogger) WithTraceID ¶
func (d *DefaultLogger) WithTraceID(traceID string) Logger
type Field ¶
type Field struct {
Key string
Value interface{}
}
Field represents a key-value pair in structured logging
type Logger ¶
type Logger interface {
// Context-first logging methods - automatically extract trace_id from context
Debug(ctx context.Context, msg string, fields ...Field)
Info(ctx context.Context, msg string, fields ...Field)
Warn(ctx context.Context, msg string, fields ...Field)
Error(ctx context.Context, msg string, err error, fields ...Field)
Fatal(ctx context.Context, msg string, err error, fields ...Field)
// Builder methods for adding metadata
WithTraceID(traceID string) Logger
WithFields(fields ...Field) Logger
WithComponent(component string) Logger
AddField(key string, value interface{}) Logger
// Context integration
ToContext(ctx context.Context) context.Context
}
Logger defines the core logging interface with context-first design. All logging methods take context.Context as the first parameter to automatically extract trace_id and other request-scoped metadata. Implementations can wrap different logging libraries like zerolog, zap, logrus, etc.
func GetLoggerFromContext ¶
Click to show internal directories.
Click to hide internal directories.