Documentation
¶
Index ¶
- func AddHook(hook LoggerHook) error
- func CloseGlobalLogger() error
- func Contains(slice []string, item string) bool
- func DecodeJSON(data []byte, v interface{}) error
- func DecodeJSONString(str string, v interface{}) error
- func EncodeJSON(v interface{}) ([]byte, error)
- func EncodeJSONString(v interface{}) string
- func FormatChainID(namespace, reference string) string
- func InitLogger(cfg *LoggingConfig) error
- func IsValidURL(str string) bool
- func ParseChainID(chainID string) []string
- func Remove(slice []string, item string) []string
- func SetGlobalLogLevel(level string) error
- func TruncateString(str string, maxLen int) string
- func Unique(slice []string) []string
- type Logger
- type LoggerHook
- type LoggerManager
- type LoggingConfig
- type MetricsHook
- type RequestIDHook
- type ZerologLogger
- func (l *ZerologLogger) Debug(msg string)
- func (l *ZerologLogger) Debugf(format string, args ...interface{})
- func (l *ZerologLogger) Error(msg string)
- func (l *ZerologLogger) Errorf(format string, args ...interface{})
- func (l *ZerologLogger) Info(msg string)
- func (l *ZerologLogger) Infof(format string, args ...interface{})
- func (l *ZerologLogger) Warn(msg string)
- func (l *ZerologLogger) Warnf(format string, args ...interface{})
- func (l *ZerologLogger) WithError(err error) Logger
- func (l *ZerologLogger) WithField(key string, value interface{}) Logger
- func (l *ZerologLogger) WithFields(fields map[string]interface{}) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes JSON bytes to an interface
func DecodeJSONString ¶
DecodeJSONString decodes JSON string to an interface
func EncodeJSON ¶
EncodeJSON encodes an interface to JSON bytes
func EncodeJSONString ¶
func EncodeJSONString(v interface{}) string
EncodeJSONString encodes an interface to JSON string
func FormatChainID ¶
FormatChainID formats namespace and reference into a chain ID
func InitLogger ¶
func InitLogger(cfg *LoggingConfig) error
InitLogger initializes the global logger
func ParseChainID ¶
ParseChainID parses a chain ID into namespace and reference
func SetGlobalLogLevel ¶
SetGlobalLogLevel sets the global log level
func TruncateString ¶
TruncateString truncates a string to a maximum length
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 ¶
GetLoggerWithComponent returns a logger with component field
func GetLoggerWithModule ¶
GetLoggerWithModule returns a logger with module field
type LoggerHook ¶
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 (*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
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) Debugf ¶
func (l *ZerologLogger) Debugf(format string, args ...interface{})
Debugf logs a formatted debug message
func (*ZerologLogger) Errorf ¶
func (l *ZerologLogger) Errorf(format string, args ...interface{})
Errorf logs a formatted error message
func (*ZerologLogger) Infof ¶
func (l *ZerologLogger) Infof(format string, args ...interface{})
Infof logs a formatted info 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