Documentation
¶
Index ¶
- Variables
- func Init(configPath string, manager *LoggerManager) error
- type AsyncCore
- func (ac *AsyncCore) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (ac *AsyncCore) Enabled(level zapcore.Level) bool
- func (ac *AsyncCore) Sync() error
- func (ac *AsyncCore) With(fields []zapcore.Field) zapcore.Core
- func (ac *AsyncCore) Write(entry zapcore.Entry, fields []zapcore.Field) error
- type Config
- type EncodingConfig
- type LogEntry
- type LogRotationConfig
- type LoggerManager
- func (lm *LoggerManager) AddLogger(name string, logger *zap.Logger) error
- func (lm *LoggerManager) GetAllLoggers() map[string]*zap.Logger
- func (lm *LoggerManager) GetLogger(name string) (*zap.Logger, error)
- func (lm *LoggerManager) RemoveLogger(name string) error
- func (lm *LoggerManager) Sync() error
- type SamplingConfig
- type SanitizationConfig
- type SanitizerCore
- type ZapWriter
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ Level: "info", OutputPaths: []string{"stdout"}, ErrorOutputPaths: []string{ "stderr", }, Development: false, LogToConsole: false, Sampling: SamplingConfig{ Initial: 100, Thereafter: 100, }, EncodingConfig: EncodingConfig{ TimeKey: "time", LevelKey: "level", NameKey: "logger", CallerKey: "caller", MessageKey: "msg", StacktraceKey: "stacktrace", LineEnding: "\n", LevelEncoder: "lowercase", TimeEncoder: "iso8601", DurationEncoder: "string", CallerEncoder: "short", }, LogRotation: LogRotationConfig{ Enabled: true, MaxSizeMB: 100, MaxBackups: 7, MaxAgeDays: 30, Compress: true, }, Sanitization: SanitizationConfig{ SensitiveFields: []string{ "password", "token", "access_token", "refresh_token", }, Mask: "****", }, }
Provides fallback logging settings for any logger not specified in log.config.json.
Functions ¶
func Init ¶
func Init(configPath string, manager *LoggerManager) error
Init initializes the loggers based on the configuration file. It should be called once at the start of the application.
Types ¶
type AsyncCore ¶
type AsyncCore struct {
// contains filtered or unexported fields
}
wraps a zapcore.Core and handles asynchronous, batched logging.
func NewAsyncCore ¶
func NewAsyncCore(core zapcore.Core, bufferSize, batchSize int, flushInterval time.Duration) *AsyncCore
initializes a new AsyncCore with batching and tracking. bufferSize: size of the buffered channel batchSize: number of log entries per batch flushInterval: maximum time to wait before flushing a batch
func (*AsyncCore) Check ¶
func (ac *AsyncCore) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry
enqueues the entry if enabled.
type Config ¶
type Config struct {
Level string `json:"level"`
OutputPaths []string `json:"outputPaths"`
ErrorOutputPaths []string `json:"errorOutputPaths"`
Development bool `json:"development"`
LogToConsole bool `json:"logToConsole"`
Sampling SamplingConfig `json:"sampling"`
EncodingConfig EncodingConfig `json:"encodingConfig"`
LogRotation LogRotationConfig `json:"logRotation"`
Sanitization SanitizationConfig `json:"sanitization"`
}
type EncodingConfig ¶
type EncodingConfig struct {
TimeKey string `json:"timeKey"`
LevelKey string `json:"levelKey"`
NameKey string `json:"nameKey"`
CallerKey string `json:"callerKey"`
MessageKey string `json:"messageKey"`
StacktraceKey string `json:"stacktraceKey"`
LineEnding string `json:"lineEnding"`
LevelEncoder string `json:"levelEncoder"`
TimeEncoder string `json:"timeEncoder"`
DurationEncoder string `json:"durationEncoder"`
CallerEncoder string `json:"callerEncoder"`
}
type LogRotationConfig ¶
type LoggerManager ¶
type LoggerManager struct {
// contains filtered or unexported fields
}
func NewLoggerManager ¶
func NewLoggerManager(logsConfigPath string) (*LoggerManager, error)
func (*LoggerManager) AddLogger ¶
func (lm *LoggerManager) AddLogger(name string, logger *zap.Logger) error
adds a new logger to the manager. Returns error if a logger with the same name already exists.
func (*LoggerManager) GetAllLoggers ¶
func (lm *LoggerManager) GetAllLoggers() map[string]*zap.Logger
Returns a copy of the map containing all loggers.
func (*LoggerManager) GetLogger ¶
func (lm *LoggerManager) GetLogger(name string) (*zap.Logger, error)
Retrieves a logger by name. If it doesn't exist, initializes with defaultConfig. Returns error instead of panicking on initialization failure.
func (*LoggerManager) RemoveLogger ¶
func (lm *LoggerManager) RemoveLogger(name string) error
Removes a logger from the manager. Returns error if logger doesn't exist.
func (*LoggerManager) Sync ¶
func (lm *LoggerManager) Sync() error
Sync flushes all loggers managed by LoggerManager. Returns a multi-error containing all sync errors encountered.
type SamplingConfig ¶
type SanitizationConfig ¶
type SanitizationConfig struct {
SensitiveFields []string `json:"sensitiveFields"`
Mask string `json:"mask"`
}
SanitizationConfig configures sensitive field sanitization.
type SanitizerCore ¶
wraps a zapcore.Core and sanitizes log entries.
func NewSanitizerCore ¶
func NewSanitizerCore(core zapcore.Core, sensitiveFields []string, mask string) *SanitizerCore
func (*SanitizerCore) Check ¶
func (s *SanitizerCore) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry
determines whether the supplied entry should be logged.
type ZapWriter ¶
type ZapWriter struct {
// contains filtered or unexported fields
}
adapter implements io.Writer and writes to Zap logger.
func NewZapWriter ¶
- logger: the Zap structured logger. - level: the log level at which messages should be logged. - prefix: the prefix to include as a separate field (optional).