logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LoggerLevelDebug    = "DEBUG"
	LoggerLevelInfo     = "INFO"
	LoggerLevelWarn     = "WARN"
	LoggerLevelError    = "ERROR"
	LoggerLevelFatal    = "FATAL"
	LoggerLevelPanic    = "PANIC"
	LoggerLevelTrace    = "TRACE"
	LoggerLevelDisabled = "DISABLED"

	ProvidersName = "loggers"
)

Variables

This section is empty.

Functions

func GetPackageLogger

func GetPackageLogger(ctx context.Context, emptyStruct interface{}) zerolog.Logger

GetPackageLogger return logger for package

func Initialize

func Initialize(parent *zerolog.Logger, emptyStruct interface{}) (log zerolog.Logger)

Initialize initilizes fields for domains and packages

func Registrate

func Registrate(ctx context.Context) context.Context

func RegistrateAndInitilize

func RegistrateAndInitilize(ctx context.Context, cfg *Config) context.Context

Types

type Config

type Config struct {
	// HumanFriendly enable writes log in human-friendly format to Out
	HumanFriendly bool `envconfig:"optional"`
	// NoColoredOutput forces logger to output things without
	// shell colorcodes.
	NoColoredOutput bool `envconfig:"optional"`
	// Show trace information (file name, line number, function name)?
	WithTrace bool `envconfig:"optional"`
	// Level is a logger's loglevel. Possible values: "DEBUG",
	// "INFO", "WARN", "ERROR", "FATAL", "TRACE". Setting this variable
	// to any other value will force INFO level.
	// Case-insensitive value.
	Level string `envconfig:"optional"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) SetDefault added in v0.3.0

func (c *Config) SetDefault()

type Field

type Field struct {
	// Name is a field name.
	Name  string
	Value interface{}
}

Field represents field information that should be passed to context.Logger.GetLogger function.

type Logger

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

Logger is a controlling structure for application's logger.

func Get

func Get(ctx context.Context) *Logger

func NewLogger

func NewLogger() *Logger

func (*Logger) GetLogger

func (l *Logger) GetLogger(name string, fields []*Field) *zerolog.Logger

GetLogger creates new logger if not exists and fills it with defined fields. If requested logger already exists - it'll be returned.

func (*Logger) Initialize

func (l *Logger) Initialize(cfg *Config)

func (*Logger) InitializeDefault

func (l *Logger) InitializeDefault()

func (*Logger) IsInitialized

func (l *Logger) IsInitialized() bool

IsInitialized returns true if logger was initialized and configured.

type TracingHook

type TracingHook struct {
	WithTrace bool
}

This adds tracing ability to zerolog. By default it will add package name to every log line. If package version specified in package name (e.g. "domains/name/v1", note "v1" ending) - it will parse version and add it as separate field. Currently only one-digit-version is supported. Note that fully enabled tracing (context.Configuration.Gowork.Logger.WithTrace set to true) might eat your performance!

func (TracingHook) Run

func (h TracingHook) Run(e *zerolog.Event, level zerolog.Level, msg string)

Jump to

Keyboard shortcuts

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