logger

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 11 Imported by: 0

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

View Source
const DefaultMaskValue = "***"

DefaultMaskValue es el valor utilizado para enmascarar datos sensibles

Variables

This section is empty.

Functions

func AddAMQPElapsed

func AddAMQPElapsed(ctx context.Context, nanos int64)

AddAMQPElapsed adds elapsed nanoseconds to the AMQP elapsed time in the context

func AddDBElapsed

func AddDBElapsed(ctx context.Context, nanos int64)

AddDBElapsed adds elapsed nanoseconds to the database elapsed time in the context

func GetAMQPCounter

func GetAMQPCounter(ctx context.Context) int64

GetAMQPCounter returns the current AMQP message count from the context

func GetAMQPElapsed

func GetAMQPElapsed(ctx context.Context) int64

GetAMQPElapsed returns the current AMQP elapsed time in nanoseconds from the context

func GetDBCounter

func GetDBCounter(ctx context.Context) int64

GetDBCounter returns the current database operation count from the context

func GetDBElapsed

func GetDBElapsed(ctx context.Context) int64

GetDBElapsed returns the current database elapsed time in nanoseconds from the context

func IncrementAMQPCounter

func IncrementAMQPCounter(ctx context.Context)

IncrementAMQPCounter increments the AMQP message counter in the context

func IncrementDBCounter

func IncrementDBCounter(ctx context.Context)

IncrementDBCounter increments the database operation counter in the context

func WithAMQPCounter

func WithAMQPCounter(ctx context.Context) context.Context

WithAMQPCounter creates a new context with an AMQP message counter and elapsed time tracker

func WithDBCounter

func WithDBCounter(ctx context.Context) context.Context

WithDBCounter creates a new context with a database operation 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 ...interface{})
	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 interface{}) 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 interface{}) LogEvent

Interface adds an interface{} field to the log event

func (*LogEventAdapter) Msg

func (lea *LogEventAdapter) Msg(msg string)

Msg logs the message

func (*LogEventAdapter) Msgf

func (lea *LogEventAdapter) Msgf(format string, args ...interface{})

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

func (*LogEventAdapter) Uint64

func (lea *LogEventAdapter) Uint64(key string, value uint64) LogEvent

Uint64 adds a uint64 field to the log event

type Logger

type Logger interface {
	Info() LogEvent
	Error() LogEvent
	Debug() LogEvent
	Warn() LogEvent
	Fatal() LogEvent
	WithContext(ctx interface{}) Logger
	WithFields(fields map[string]interface{}) 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]interface{}) map[string]interface{}

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 interface{}) interface{}

FilterValue filters sensitive data from interface{} values

func (*SensitiveDataFilter) Run

Run implements zerolog.Hook interface to filter sensitive data

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) Info

func (l *ZeroLogger) Info() LogEvent

Info creates an info-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 interface{}) Logger

WithContext returns a logger with context information attached.

func (*ZeroLogger) WithFields

func (l *ZeroLogger) WithFields(fields map[string]interface{}) Logger

WithFields returns a logger with additional fields attached to all log entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL