logger

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PluginName = "logs"

PluginName declares plugin name.

Variables

This section is empty.

Functions

func ColoredHashedNameEncoder

func ColoredHashedNameEncoder(s string, enc zapcore.PrimitiveArrayEncoder)

ColoredHashedNameEncoder colorizes service names and assigns different colors to different names.

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.

func UTCTimeEncoder

func UTCTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

UTCTimeEncoder encodes time into short UTC specific timestamp.

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 string `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"`

	// 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:"errorOutput"`
}

func (*Config) BuildLogger

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

ZapConfig converts config into Zap configuration.

func (*Config) InitDefault

func (cfg *Config) InitDefault()

Initialize default logger

type Logger

type Logger interface {
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
}

Logger is an general RR log interface

type StdLogAdapter added in v2.0.2

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

StdLogAdapter can be passed to the http.Server or any place which required standard logger to redirect output to the logger plugin

func NewStdAdapter added in v2.0.2

func NewStdAdapter(log Logger) *StdLogAdapter

NewStdAdapter constructs StdLogAdapter

func (*StdLogAdapter) Write added in v2.0.2

func (s *StdLogAdapter) Write(p []byte) (n int, err error)

Write io.Writer interface implementation

type WithLogger

type WithLogger interface {
	With(keyvals ...interface{}) Logger
}

With creates a child logger and adds structured context to it

type ZapAdapter

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

func NewZapAdapter

func NewZapAdapter(zapLogger *zap.Logger) *ZapAdapter

Create NewZapAdapter which uses general log interface

func (*ZapAdapter) Debug

func (log *ZapAdapter) Debug(msg string, keyvals ...interface{})

func (*ZapAdapter) Error

func (log *ZapAdapter) Error(msg string, keyvals ...interface{})

func (*ZapAdapter) Info

func (log *ZapAdapter) Info(msg string, keyvals ...interface{})

func (*ZapAdapter) Warn

func (log *ZapAdapter) Warn(msg string, keyvals ...interface{})

func (*ZapAdapter) With

func (log *ZapAdapter) With(keyvals ...interface{}) Logger

type ZapLogger

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

ZapLogger manages zap logger.

func (*ZapLogger) Init

func (z *ZapLogger) Init(cfg config.Configurer) error

Init logger service.

func (*ZapLogger) NamedLogger

func (z *ZapLogger) NamedLogger(name string) (Logger, error)

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

func (*ZapLogger) Provides

func (z *ZapLogger) Provides() []interface{}

Provides declares factory methods.

func (*ZapLogger) ServiceLogger

func (z *ZapLogger) ServiceLogger(n endure.Named) (Logger, error)

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

Jump to

Keyboard shortcuts

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