logger

package module
v0.0.0-...-7bb5cce Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHook

func AddHook(hook LoggerHook) error

AddHook adds a hook to the global logger

func CloseGlobalLogger

func CloseGlobalLogger() error

CloseGlobalLogger closes the global logger

func Contains

func Contains(slice []string, item string) bool

Contains checks if a slice contains a string

func DecodeJSON

func DecodeJSON(data []byte, v interface{}) error

DecodeJSON decodes JSON bytes to an interface

func DecodeJSONString

func DecodeJSONString(str string, v interface{}) error

DecodeJSONString decodes JSON string to an interface

func EncodeJSON

func EncodeJSON(v interface{}) ([]byte, error)

EncodeJSON encodes an interface to JSON bytes

func EncodeJSONString

func EncodeJSONString(v interface{}) string

EncodeJSONString encodes an interface to JSON string

func FormatChainID

func FormatChainID(namespace, reference string) string

FormatChainID formats namespace and reference into a chain ID

func InitLogger

func InitLogger(cfg *LoggingConfig) error

InitLogger initializes the global logger

func IsValidURL

func IsValidURL(str string) bool

IsValidURL checks if a string is a valid URL

func ParseChainID

func ParseChainID(chainID string) []string

ParseChainID parses a chain ID into namespace and reference

func Remove

func Remove(slice []string, item string) []string

Remove removes a string from a slice

func SetGlobalLogLevel

func SetGlobalLogLevel(level string) error

SetGlobalLogLevel sets the global log level

func TruncateString

func TruncateString(str string, maxLen int) string

TruncateString truncates a string to a maximum length

func Unique

func Unique(slice []string) []string

Unique removes duplicate strings from a slice

Types

type Logger

type Logger interface {
	Debug(msg string)
	Debugf(format string, args ...interface{})
	Info(msg string)
	Infof(format string, args ...interface{})
	Warn(msg string)
	Warnf(format string, args ...interface{})
	Error(msg string)
	Errorf(format string, args ...interface{})
	WithField(key string, value interface{}) Logger
	WithFields(fields map[string]interface{}) Logger
	WithError(err error) Logger
}

Logger interface defines the logging methods

func GetGlobalLogger

func GetGlobalLogger() Logger

GetGlobalLogger returns the global logger instance

func GetLoggerWithComponent

func GetLoggerWithComponent(component string) Logger

GetLoggerWithComponent returns a logger with component field

func GetLoggerWithModule

func GetLoggerWithModule(module string) Logger

GetLoggerWithModule returns a logger with module field

type LoggerHook

type LoggerHook interface {
	Fire(level zerolog.Level, msg string) error
}

LoggerHook interface for custom hooks

type LoggerManager

type LoggerManager struct {
	// contains filtered or unexported fields
}

LoggerManager manages logger instances and configuration

func NewLoggerManager

func NewLoggerManager(cfg *LoggingConfig) (*LoggerManager, error)

NewLoggerManager creates a new logger manager with the given configuration

func (*LoggerManager) Close

func (m *LoggerManager) Close() error

Close closes the logger and flushes any buffered log entries

func (*LoggerManager) GetLogger

func (m *LoggerManager) GetLogger() Logger

GetLogger returns the logger instance

func (*LoggerManager) SetLevel

func (m *LoggerManager) SetLevel(level string) error

SetLevel changes the log level

type LoggingConfig

type LoggingConfig struct {
	Level      string `mapstructure:"level"`
	Format     string `mapstructure:"format"`
	Output     string `mapstructure:"output"` // stdout, stderr, file
	FilePath   string `mapstructure:"file_path"`
	MaxSize    int    `mapstructure:"max_size"`
	MaxBackups int    `mapstructure:"max_backups"`
	MaxAge     int    `mapstructure:"max_age"`
}

func DefaultLoggingConfig

func DefaultLoggingConfig() LoggingConfig

type MetricsHook

type MetricsHook struct {
	// contains filtered or unexported fields
}

MetricsHook tracks log metrics

func NewMetricsHook

func NewMetricsHook() *MetricsHook

NewMetricsHook creates a new metrics hook

func (*MetricsHook) Fire

func (h *MetricsHook) Fire(level zerolog.Level, msg string) error

Fire is called when a log entry is made

func (*MetricsHook) GetCounts

func (h *MetricsHook) GetCounts() (errors, warns, infos, debugs int64)

GetCounts returns the current counts

type RequestIDHook

type RequestIDHook struct{}

RequestIDHook transforms request_id to req_id

func NewRequestIDHook

func NewRequestIDHook() *RequestIDHook

NewRequestIDHook creates a new request ID hook

func (*RequestIDHook) Fire

func (h *RequestIDHook) Fire(level zerolog.Level, msg string) error

Fire transforms request_id field to req_id

type ZerologLogger

type ZerologLogger struct {
	// contains filtered or unexported fields
}

ZerologLogger implements Logger interface using zerolog

func NewZerologLogger

func NewZerologLogger(logger zerolog.Logger) *ZerologLogger

NewZerologLogger creates a new ZerologLogger instance

func (*ZerologLogger) Debug

func (l *ZerologLogger) Debug(msg string)

Debug logs a debug message

func (*ZerologLogger) Debugf

func (l *ZerologLogger) Debugf(format string, args ...interface{})

Debugf logs a formatted debug message

func (*ZerologLogger) Error

func (l *ZerologLogger) Error(msg string)

Error logs an error message

func (*ZerologLogger) Errorf

func (l *ZerologLogger) Errorf(format string, args ...interface{})

Errorf logs a formatted error message

func (*ZerologLogger) Info

func (l *ZerologLogger) Info(msg string)

Info logs an info message

func (*ZerologLogger) Infof

func (l *ZerologLogger) Infof(format string, args ...interface{})

Infof logs a formatted info message

func (*ZerologLogger) Warn

func (l *ZerologLogger) Warn(msg string)

Warn logs a warning message

func (*ZerologLogger) Warnf

func (l *ZerologLogger) Warnf(format string, args ...interface{})

Warnf logs a formatted warning message

func (*ZerologLogger) WithError

func (l *ZerologLogger) WithError(err error) Logger

WithError adds an error field to the logger

func (*ZerologLogger) WithField

func (l *ZerologLogger) WithField(key string, value interface{}) Logger

WithField adds a field to the logger

func (*ZerologLogger) WithFields

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

WithFields adds multiple fields to the logger

Jump to

Keyboard shortcuts

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