logger

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	EncodingConsole bool   `yaml:"encoding_console" env:"ENCODING_CONSOLE" default:"false" usage:"allows to set user-friendly formatting" example:"false"`
	Level           string `yaml:"level" env:"LEVEL" default:"info" usage:"allows to set custom logger level" example:"info"`
	Trace           string `yaml:"trace" env:"TRACE" default:"fatal" usage:"allows to set custom trace level" example:"fatal"`
	WithCaller      bool   `yaml:"with_caller" env:"WITH_CALLER" default:"false" usage:"allows to show stack trace" example:"false"`
	WithStackTrace  bool   `yaml:"with_stack_trace" env:"WITH_STACK_TRACE" default:"false" usage:"allows to show stack trace" example:"false"`
}

func (*Config) Validate

func (c *Config) Validate() error

type ExtendedLogger

type ExtendedLogger interface {
	Logger
	Std() *log.Logger
	Sugar() *sugaredLogger
}

func DefaultExtended added in v0.1.0

func DefaultExtended() ExtendedLogger

Default returns default extended logger instance

func NewExtended

func NewExtended(opts ...Option) ExtendedLogger

NewExtended - init new extended logger with options

func WithExtended added in v0.2.6

func WithExtended(l ExtendedLogger, args ...any) ExtendedLogger

WithExtended allows to provide zap.SugaredLogger as common interface.

type LogFormat

type LogFormat string
const (
	LoggerFormatConsole LogFormat = "console"
	LoggerFormatJSON    LogFormat = "json"
)

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
	LogLevelFatal LogLevel = "fatal"
	LogLevelPanic LogLevel = "panic"
)

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Debug(...any)
	Debugln(...any)
	Debugf(template string, args ...any)
	Debugw(msg string, keysAndValues ...any)

	Info(...any)
	Infoln(...any)
	Infof(template string, args ...any)
	Infow(msg string, keysAndValues ...any)

	Warn(...any)
	Warnln(...any)
	Warnf(template string, args ...any)
	Warnw(msg string, keysAndValues ...any)

	Error(...any)
	Errorln(...any)
	Errorf(template string, args ...any)
	Errorw(msg string, keysAndValues ...any)

	Fatal(...any)
	Fatalln(...any)
	Fatalf(template string, args ...any)
	Fatalw(msg string, keysAndValues ...any)

	Panic(...any)
	Panicln(...any)
	Panicf(template string, args ...any)
	Panicw(msg string, keysAndValues ...any)

	Sync() error
}

Logger common interface

func Default

func Default() Logger

Default returns default logger instance

func ForTests

func ForTests(t testingT) Logger

ForTests wrapped logger for tests.

func New

func New(opts ...Option) Logger

New - init new logger with options

func With added in v0.2.6

func With(l Logger, args ...any) Logger

With allows to provide zap.SugaredLogger as common interface.

type Option

type Option func(*logger)

func WithAppName

func WithAppName(v string) Option

WithAppName allows to set application name to logger fields.

func WithAppVersion

func WithAppVersion(v string) Option

WithAppVersion allows to set application version to logger fields.

func WithCaller

func WithCaller(v bool) Option

func WithConfig

func WithConfig(v Config) Option

func WithConsoleColored

func WithConsoleColored(v bool) Option

WithConsoleColored allows to set colored console output.

func WithLogFormat

func WithLogFormat(v LogFormat) Option

func WithLogLevel

func WithLogLevel(v LogLevel) Option

func WithStackTrace

func WithStackTrace(v bool) Option

func WithTimeKey

func WithTimeKey(v string) Option

func WithZapOption

func WithZapOption(v zap.Option) Option

WithZapOption allows to set zap.Option.

type Sink

type Sink = zap.Sink

Sink defines the interface to write to and close logger destinations. Type alias.

type WriteSyncer

type WriteSyncer = zapcore.WriteSyncer

WriteSyncer is an io.Writer that can also flush any buffered data. Note that *os.File (and thus, os.Stderr and os.Stdout) implement WriteSyncer. Type alias.

Jump to

Keyboard shortcuts

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