Documentation
¶
Overview ¶
Package logger provides logging functionality with zerolog adapter
Package logger provides filtering capabilities for sensitive data in log output.
Package logger defines the logging interface used throughout the application. It provides a contract for structured logging implementations.
Index ¶
- Constants
- func AddAMQPElapsed(ctx context.Context, nanos int64)
- func AddDBElapsed(ctx context.Context, nanos int64)
- func GetAMQPCounter(ctx context.Context) int64
- func GetAMQPElapsed(ctx context.Context) int64
- func GetDBCounter(ctx context.Context) int64
- func GetDBElapsed(ctx context.Context) int64
- func IncrementAMQPCounter(ctx context.Context)
- func IncrementDBCounter(ctx context.Context)
- func WithAMQPCounter(ctx context.Context) context.Context
- func WithDBCounter(ctx context.Context) context.Context
- type FilterConfig
- type LogEvent
- type LogEventAdapter
- func (lea *LogEventAdapter) Bytes(key string, val []byte) LogEvent
- func (lea *LogEventAdapter) Dur(key string, d time.Duration) LogEvent
- func (lea *LogEventAdapter) Err(err error) LogEvent
- func (lea *LogEventAdapter) Int(key string, value int) LogEvent
- func (lea *LogEventAdapter) Int64(key string, value int64) LogEvent
- func (lea *LogEventAdapter) Interface(key string, i any) LogEvent
- func (lea *LogEventAdapter) Msg(msg string)
- func (lea *LogEventAdapter) Msgf(format string, args ...any)
- func (lea *LogEventAdapter) Str(key, value string) LogEvent
- func (lea *LogEventAdapter) Uint64(key string, value uint64) LogEvent
- type Logger
- type SensitiveDataFilter
- type ZeroLogger
Constants ¶
const DefaultMaskValue = "***"
DefaultMaskValue es el valor utilizado para enmascarar datos sensibles
const (
// DefaultMaxDepth is the default maximum recursion depth for filtering
DefaultMaxDepth = 8
)
Variables ¶
This section is empty.
Functions ¶
func AddAMQPElapsed ¶
AddAMQPElapsed adds elapsed nanoseconds to the AMQP elapsed time in the context
func AddDBElapsed ¶
AddDBElapsed adds elapsed nanoseconds to the database elapsed time in the context
func GetAMQPCounter ¶
GetAMQPCounter returns the current AMQP message count from the context
func GetAMQPElapsed ¶
GetAMQPElapsed returns the current AMQP elapsed time in nanoseconds from the context
func GetDBCounter ¶
GetDBCounter returns the current database operation count from the context
func GetDBElapsed ¶
GetDBElapsed returns the current database elapsed time in nanoseconds from the context
func IncrementAMQPCounter ¶
IncrementAMQPCounter increments the AMQP message counter in the context
func IncrementDBCounter ¶
IncrementDBCounter increments the database operation counter in the context
func WithAMQPCounter ¶
WithAMQPCounter creates a new context with an AMQP message counter and elapsed time tracker
Types ¶
type FilterConfig ¶
type FilterConfig struct {
// SensitiveFields contains field names that should be masked in logs
SensitiveFields []string
// MaskValue is the value used to replace sensitive data (default: "***")
MaskValue string
}
FilterConfig defines the configuration for sensitive data filtering
func DefaultFilterConfig ¶
func DefaultFilterConfig() *FilterConfig
DefaultFilterConfig returns a default configuration with common sensitive field names
type LogEvent ¶
type LogEvent interface {
Msg(msg string)
Msgf(format string, args ...any)
Err(err error) LogEvent
Str(key, value string) LogEvent
Int(key string, value int) LogEvent
Int64(key string, value int64) LogEvent
Uint64(key string, value uint64) LogEvent
Dur(key string, d time.Duration) LogEvent
Interface(key string, i any) LogEvent
Bytes(key string, val []byte) LogEvent
}
LogEvent represents a structured log event that can be built with fields and sent. It provides methods for adding various field types and sending the final log message.
type LogEventAdapter ¶
type LogEventAdapter struct {
// contains filtered or unexported fields
}
LogEventAdapter adapts zerolog events to our logger interface
func (*LogEventAdapter) Bytes ¶
func (lea *LogEventAdapter) Bytes(key string, val []byte) LogEvent
Bytes adds a byte slice field to the log event
func (*LogEventAdapter) Dur ¶
func (lea *LogEventAdapter) Dur(key string, d time.Duration) LogEvent
Dur adds a duration field to the log event
func (*LogEventAdapter) Err ¶
func (lea *LogEventAdapter) Err(err error) LogEvent
Err adds an error to the log event
func (*LogEventAdapter) Int ¶
func (lea *LogEventAdapter) Int(key string, value int) LogEvent
Int adds an integer field to the log event
func (*LogEventAdapter) Int64 ¶
func (lea *LogEventAdapter) Int64(key string, value int64) LogEvent
Int64 adds an int64 field to the log event
func (*LogEventAdapter) Interface ¶
func (lea *LogEventAdapter) Interface(key string, i any) LogEvent
Interface adds an any field to the log event
func (*LogEventAdapter) Msgf ¶
func (lea *LogEventAdapter) Msgf(format string, args ...any)
Msgf logs a formatted message
func (*LogEventAdapter) Str ¶
func (lea *LogEventAdapter) Str(key, value string) LogEvent
Str adds a string field to the log event
type Logger ¶
type Logger interface {
Info() LogEvent
Error() LogEvent
Debug() LogEvent
Warn() LogEvent
Fatal() LogEvent
WithContext(ctx any) Logger
WithFields(fields map[string]any) Logger
}
Logger defines the contract for structured logging throughout the application. It provides methods for creating log events at different severity levels and for contextual logging.
type SensitiveDataFilter ¶
type SensitiveDataFilter struct {
// contains filtered or unexported fields
}
SensitiveDataFilter implements zerolog.Hook to filter sensitive data from logs
func NewSensitiveDataFilter ¶
func NewSensitiveDataFilter(config *FilterConfig) *SensitiveDataFilter
NewSensitiveDataFilter creates a new filter with the given configuration
func (*SensitiveDataFilter) FilterFields ¶
func (f *SensitiveDataFilter) FilterFields(fields map[string]any) map[string]any
FilterFields filters a map of fields for sensitive data
func (*SensitiveDataFilter) FilterString ¶
func (f *SensitiveDataFilter) FilterString(key, value string) string
FilterString filters sensitive data from string values
func (*SensitiveDataFilter) FilterValue ¶
func (f *SensitiveDataFilter) FilterValue(key string, value any) any
FilterValue filters sensitive data from any values
type ZeroLogger ¶
type ZeroLogger struct {
// contains filtered or unexported fields
}
ZeroLogger wraps zerolog.Logger to implement the Logger interface. It provides structured logging functionality with configurable output formatting.
func New ¶
func New(level string, pretty bool) *ZeroLogger
New creates a new ZeroLogger instance with the specified log level and formatting options. If pretty is true, output will be formatted for human readability.
func NewWithFilter ¶
func NewWithFilter(level string, pretty bool, filterConfig *FilterConfig) *ZeroLogger
NewWithFilter creates a new ZeroLogger instance with custom filter configuration. This allows applications to customize which fields are considered sensitive.
func (*ZeroLogger) Debug ¶
func (l *ZeroLogger) Debug() LogEvent
Debug creates a debug-level log event
func (*ZeroLogger) Error ¶
func (l *ZeroLogger) Error() LogEvent
func (*ZeroLogger) Fatal ¶
func (l *ZeroLogger) Fatal() LogEvent
Fatal creates a fatal-level log event
func (*ZeroLogger) Warn ¶
func (l *ZeroLogger) Warn() LogEvent
Warn creates a warning-level log event
func (*ZeroLogger) WithContext ¶
func (l *ZeroLogger) WithContext(ctx any) Logger
WithContext returns a logger with context information attached.
func (*ZeroLogger) WithFields ¶
func (l *ZeroLogger) WithFields(fields map[string]any) Logger
WithFields returns a logger with additional fields attached to all log entries.