Documentation
¶
Index ¶
- Constants
- func ConfigureLogLevelLogger(logLevel string) zap.Config
- func FromContext(ctx context.Context) *zap.SugaredLogger
- func NewAppLogger() *zap.SugaredLogger
- func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context
- type LogAdapter
- func (a *LogAdapter) Debug(ctx context.Context, message string, fields map[string]interface{})
- func (a *LogAdapter) Error(ctx context.Context, message string, err error, fields map[string]interface{})
- func (a *LogAdapter) Info(ctx context.Context, message string, fields map[string]interface{})
- func (a *LogAdapter) Warn(ctx context.Context, message string, fields map[string]interface{})
- func (a *LogAdapter) Warning(ctx context.Context, message string, fields map[string]interface{})
- func (a *LogAdapter) WithFields(fields map[string]interface{}) Logger
- type Logger
- type NopLogger
- func (l *NopLogger) Debug(ctx context.Context, message string, fields map[string]interface{})
- func (l *NopLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
- func (l *NopLogger) Info(ctx context.Context, message string, fields map[string]interface{})
- func (l *NopLogger) Warn(ctx context.Context, message string, fields map[string]interface{})
- func (l *NopLogger) Warning(ctx context.Context, message string, fields map[string]interface{})
- func (l *NopLogger) WithFields(fields map[string]interface{}) Logger
- type SimpleLogger
- type StdLogger
- func (l *StdLogger) Debug(ctx context.Context, message string, fields map[string]interface{})
- func (l *StdLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
- func (l *StdLogger) Info(ctx context.Context, message string, fields map[string]interface{})
- func (l *StdLogger) IsDebugEnabled() bool
- func (l *StdLogger) SetDebug(debug bool)
- func (l *StdLogger) Warn(ctx context.Context, message string, fields map[string]interface{})
- func (l *StdLogger) Warning(ctx context.Context, message string, fields map[string]interface{})
- func (l *StdLogger) WithFields(fields map[string]interface{}) Logger
- type ZapLogger
- func (l *ZapLogger) Debug(ctx context.Context, message string, fields map[string]interface{})
- func (l *ZapLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
- func (l *ZapLogger) Info(ctx context.Context, message string, fields map[string]interface{})
- func (l *ZapLogger) Sugar() *zap.SugaredLogger
- func (l *ZapLogger) Sync() error
- func (l *ZapLogger) Warn(ctx context.Context, message string, fields map[string]interface{})
- func (l *ZapLogger) Warning(ctx context.Context, message string, fields map[string]interface{})
- func (l *ZapLogger) WithFields(fields map[string]interface{}) Logger
Constants ¶
const ( TimestampFormat = "2006-01-02 15:04:05" InfoLevel = "info" DebugLevel = "debug" ErrorLevel = "error" )
Logger constants
Variables ¶
This section is empty.
Functions ¶
func ConfigureLogLevelLogger ¶
Returns logger conifg depending on the log level
func FromContext ¶
func FromContext(ctx context.Context) *zap.SugaredLogger
FromContext returns the logger in the context. If no logger is found, it returns a cached default logger (initialized once).
func NewAppLogger ¶
func NewAppLogger() *zap.SugaredLogger
AppLogger returns a new AppLogger instance
func WithLogger ¶
WithLogger returns a copy of parent context in which the value associated with logger key is the supplied logger.
Types ¶
type LogAdapter ¶ added in v1.3.41
type LogAdapter struct {
// contains filtered or unexported fields
}
LogAdapter wraps a SimpleLogger to implement the full Logger interface. This allows using simpler loggers (like zap.SugaredLogger) where the full interface is expected.
func NewLogAdapter ¶ added in v1.3.41
func NewLogAdapter(simple SimpleLogger) *LogAdapter
NewLogAdapter creates a new LogAdapter wrapping the given SimpleLogger.
func (*LogAdapter) Debug ¶ added in v1.3.41
func (a *LogAdapter) Debug(ctx context.Context, message string, fields map[string]interface{})
Debug implements Logger.
func (*LogAdapter) Error ¶ added in v1.3.41
func (a *LogAdapter) Error(ctx context.Context, message string, err error, fields map[string]interface{})
Error implements Logger.
func (*LogAdapter) Info ¶ added in v1.3.41
func (a *LogAdapter) Info(ctx context.Context, message string, fields map[string]interface{})
Info implements Logger.
func (*LogAdapter) Warn ¶ added in v1.3.41
func (a *LogAdapter) Warn(ctx context.Context, message string, fields map[string]interface{})
Warn implements Logger.
func (*LogAdapter) Warning ¶ added in v1.3.41
func (a *LogAdapter) Warning(ctx context.Context, message string, fields map[string]interface{})
Warning is an alias for Warn.
func (*LogAdapter) WithFields ¶ added in v1.3.41
func (a *LogAdapter) WithFields(fields map[string]interface{}) Logger
WithFields implements Logger.
type Logger ¶ added in v1.3.41
type Logger interface {
// Info logs an informational message with optional structured fields.
Info(ctx context.Context, message string, fields map[string]interface{})
// Debug logs a debug message with optional structured fields.
Debug(ctx context.Context, message string, fields map[string]interface{})
// Warn logs a warning message with optional structured fields.
Warn(ctx context.Context, message string, fields map[string]interface{})
// Warning is an alias for Warn for compatibility with different naming conventions.
Warning(ctx context.Context, message string, fields map[string]interface{})
// Error logs an error message with the error and optional structured fields.
Error(ctx context.Context, message string, err error, fields map[string]interface{})
// WithFields returns a new Logger with the given fields added to all log messages.
// This is useful for adding contextual information that should appear in all subsequent logs.
WithFields(fields map[string]interface{}) Logger
}
Logger defines the standard interface for structured logging throughout goLibMyCarrier packages. Implementations should provide structured logging with context and field support. This interface is designed to be flexible enough for use in libraries while supporting context propagation for tracing and structured fields for observability.
type NopLogger ¶ added in v1.3.41
type NopLogger struct{}
NopLogger is a logger that does nothing. Useful for testing or when logging is not needed.
func (*NopLogger) Error ¶ added in v1.3.41
func (l *NopLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
Error does nothing.
func (*NopLogger) WithFields ¶ added in v1.3.41
WithFields returns the same NopLogger.
type SimpleLogger ¶ added in v1.3.41
type SimpleLogger interface {
Info(args ...interface{})
Infof(format string, args ...interface{})
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Warn(args ...interface{})
Warnf(format string, args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
}
SimpleLogger defines a simpler logging interface for cases where context and structured fields are not needed. This is compatible with most basic loggers.
type StdLogger ¶ added in v1.3.41
type StdLogger struct {
// contains filtered or unexported fields
}
StdLogger is a simple logger that uses the standard library's log package. It provides structured logging with optional debug mode.
func NewStdLogger ¶ added in v1.3.41
NewStdLogger creates a new StdLogger. If debug is true, debug-level messages will be logged.
func NewStdLoggerWithPrefix ¶ added in v1.3.41
NewStdLoggerWithPrefix creates a new StdLogger with a custom prefix.
func (*StdLogger) Debug ¶ added in v1.3.41
Debug logs a debug message (only if debug mode is enabled).
func (*StdLogger) Error ¶ added in v1.3.41
func (l *StdLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
Error logs an error message.
func (*StdLogger) IsDebugEnabled ¶ added in v1.3.41
IsDebugEnabled returns whether debug logging is enabled.
func (*StdLogger) WithFields ¶ added in v1.3.41
WithFields returns a new StdLogger with the given fields added.
type ZapLogger ¶ added in v1.3.41
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger wraps a zap.SugaredLogger to implement the Logger interface. This allows using zap loggers with packages that expect the Logger interface.
func NewZapLogger ¶ added in v1.3.41
func NewZapLogger(sugar *zap.SugaredLogger) *ZapLogger
NewZapLogger creates a new ZapLogger wrapping the given SugaredLogger.
func NewZapLoggerFromConfig ¶ added in v1.3.41
func NewZapLoggerFromConfig() *ZapLogger
NewZapLoggerFromConfig creates a new ZapLogger using the standard app logger configuration. This is a convenience function that combines NewAppLogger and NewZapLogger.
func (*ZapLogger) Error ¶ added in v1.3.41
func (l *ZapLogger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
Error logs an error message with structured fields.
func (*ZapLogger) Info ¶ added in v1.3.41
Info logs an informational message with structured fields.
func (*ZapLogger) Sugar ¶ added in v1.3.41
func (l *ZapLogger) Sugar() *zap.SugaredLogger
Sugar returns the underlying zap.SugaredLogger. This allows access to the full zap API when needed.
func (*ZapLogger) Sync ¶ added in v1.3.41
Sync flushes any buffered log entries. Applications should take care to call Sync before exiting.
func (*ZapLogger) WithFields ¶ added in v1.3.41
WithFields returns a new ZapLogger with the given fields added.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package loggertest provides test fixtures and mocks for testing code that uses the logger package.
|
Package loggertest provides test fixtures and mocks for testing code that uses the logger package. |