logger

package module
v4.2.15 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 10 Imported by: 3

README

Documentation

Index

Constants

View Source
const PluginName = "logs"

PluginName declares plugin name.

Variables

This section is empty.

Functions

func ColoredLevelEncoder

func ColoredLevelEncoder(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

ColoredLevelEncoder colorizes log levels.

func ColoredNameEncoder

func ColoredNameEncoder(s string, enc zapcore.PrimitiveArrayEncoder)

ColoredNameEncoder colorizes service names.

Types

type ChannelConfig

type ChannelConfig struct {
	// Dedicated channels per logger. By default logger allocated via named logger.
	Channels map[string]*Config `mapstructure:"channels"`
}

ChannelConfig configures loggers per channel.

type Config

type Config struct {
	// Mode configures logger based on some default template (development, production, off).
	Mode Mode `mapstructure:"mode"`

	// Level is the minimum enabled logging level. Note that this is a dynamic
	// level, so calling ChannelConfig.Level.SetLevel will atomically change the log
	// level of all loggers descended from this config.
	Level string `mapstructure:"level"`

	// Logger line ending. Default: "\n" for the all modes except production
	LineEnding string `mapstructure:"line_ending"`

	// Encoding sets the logger's encoding. InitDefault values are "json" and
	// "console", as well as any third-party encodings registered via
	// RegisterEncoder.
	Encoding string `mapstructure:"encoding"`

	// Output is a list of URLs or file paths to write logging output to.
	// See Open for details.
	Output []string `mapstructure:"output"`

	// ErrorOutput is a list of URLs to write internal logger errors to.
	// The default is standard error.
	//
	// Note that this setting only affects internal errors; for sample code that
	// sends error-level logs to a different location from info- and debug-level
	// logs, see the package-level AdvancedConfiguration example.
	ErrorOutput []string `mapstructure:"err_output"`

	// File logger options
	FileLogger *FileLoggerConfig `mapstructure:"file_logger_options"`
}

func (*Config) BuildLogger

func (cfg *Config) BuildLogger() (*zap.Logger, error)

BuildLogger converts config into Zap configuration.

func (*Config) InitDefault

func (cfg *Config) InitDefault()

InitDefault Initialize default logger

type Configurer

type Configurer interface {
	// UnmarshalKey takes a single key and unmarshal it into a Struct.
	UnmarshalKey(name string, out any) error
	// Has checks if config section exists.
	Has(name string) bool
}

type FileLoggerConfig

type FileLoggerConfig struct {
	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	LogOutput string `mapstructure:"log_output"`

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `mapstructure:"max_size"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `mapstructure:"max_age"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `mapstructure:"max_backups"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `mapstructure:"compress"`
}

FileLoggerConfig structure represents configuration for the file logger

func (*FileLoggerConfig) InitDefaults

func (fl *FileLoggerConfig) InitDefaults() *FileLoggerConfig

type Log

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

func NewLogger

func NewLogger(channels ChannelConfig, base *zap.Logger) *Log

func (*Log) NamedLogger

func (l *Log) NamedLogger(name string) *zap.Logger

type Logger

type Logger interface {
	NamedLogger(name string) *zap.Logger
}

Logger is the main logger interface to provide a named (per-plugin) logger

type Mode

type Mode string

Mode represents available logger modes

type Plugin

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

Plugin manages zap logger.

func (*Plugin) Init

func (p *Plugin) Init(cfg Configurer) error

Init logger service.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns user-friendly plugin name

func (*Plugin) Provides

func (p *Plugin) Provides() []*dep.Out

func (*Plugin) Serve

func (p *Plugin) Serve() chan error

func (*Plugin) ServiceLogger

func (p *Plugin) ServiceLogger() *Log

ServiceLogger returns logger dedicated to the specific channel. Similar to Named() but also reads the core params.

func (*Plugin) Stop

func (p *Plugin) Stop(context.Context) error

Jump to

Keyboard shortcuts

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