logger

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: AGPL-3.0, ISC Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const KeyNodeID = "NodeID"
View Source
const (
	TimeLocationLocal = "Local"
)

Variables

This section is empty.

Functions

func ClearAllContext

func ClearAllContext()

ClearAllContext will clear all context keys

func ClearContext

func ClearContext(key string)

ClearContext will clear a context key from all loggers

func InitializeGlobalLogger

func InitializeGlobalLogger()

InitializeGlobalLogger initializes global logger with default configuration if it hasn't been initialized already. If it has been initialized, does nothing.

func PrintDebug

func PrintDebug()

PrintDebug prints debug information about loggers to stdout.

func SetContext

func SetContext(key string, value interface{})

SetContext sets context for all loggers

func UpdateGlobalConfig

func UpdateGlobalConfig(config GlobalConfig)

UpdateGlobalConfig Updates global config and updates all loggers accordingly Sets only fields that are non-nil

func UpdateGlobalConfigFromFile

func UpdateGlobalConfigFromFile(fileURL string) error

UpdateGlobalConfigFromFile reads the file and parses it as YAML. Global logger configuration is updated accordingly. In case of an error, logger won't be updated.

Types

type Context

type Context map[string]interface{}

type ContextLogger

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

func (*ContextLogger) ChangeLevel

func (c *ContextLogger) ChangeLevel(newLevel LogLevel)

ChangeLevel changes the level of the context logger.

func (*ContextLogger) Debug

func (c *ContextLogger) Debug(format string, args ...interface{})

func (*ContextLogger) Error

func (c *ContextLogger) Error(format string, args ...interface{})

func (*ContextLogger) GetLevel

func (c *ContextLogger) GetLevel() LogLevel

func (*ContextLogger) Info

func (c *ContextLogger) Info(format string, args ...interface{})

func (*ContextLogger) Trace

func (c *ContextLogger) Trace(format string, args ...interface{})

func (*ContextLogger) Warning

func (c *ContextLogger) Warning(format string, args ...interface{})

type GlobalConfig

type GlobalConfig struct {
	DefaultLevel    LogLevel
	PackageLevels   map[string]LogLevel
	Writer          io.Writer // Writer for log output. By default os.Stdout
	ConsoleFormat   bool      // set to true for human-readable output. By default, uses JSON output.
	ShowCaller      bool      // set to true to show caller in the log message. By default, true.
	TimeLocation    string    // the location for displaying time, by default OS local time.
	ShowGoroutineID bool      // set to true to add goroutine id to the messages. By default, false.
	ShowNodeID      bool      // set to true to add node id to the messages. By default, false.
}

func BenchmarkConfiguration

func BenchmarkConfiguration() GlobalConfig

BenchmarkConfiguration is a quiet configuration meant for benchmarks.

type LogLevel

type LogLevel uint
const (
	NONE LogLevel = iota
	ERROR
	WARNING
	INFO
	DEBUG
	TRACE
)

func LevelFromString

func LevelFromString(s string) LogLevel

type Logger

type Logger interface {
	Trace(format string, args ...interface{})
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warning(format string, args ...interface{})
	Error(format string, args ...interface{})
	// ChangeLevel changes logger level to the newLevel
	ChangeLevel(newLevel LogLevel)
	GetLevel() LogLevel
}

func Create

func Create(name string) Logger

Create creates custom named logger

func CreateForPackage

func CreateForPackage() Logger

CreateForPackage creates logger named after the caller package.

type PackageNameResolver

type PackageNameResolver struct {
	BasePackage string
	Depth       int
}

func (*PackageNameResolver) PackageName

func (r *PackageNameResolver) PackageName() string

Jump to

Keyboard shortcuts

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