logging

package
v0.3.2-g4eb5504 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const (
	LogConfigFile       = "config.yaml"
	LogConfigDir        = ".slf4go"
	LogConfigDirEnvVar  = "SLF4GO_CONFIG_DIR"
	LogConfigFileEnvVar = "SLF4GO_CONFIG_FILE"

	DefaultLoggerName   = "default"
	DefaultLoggerLevel  = "INFO"
	DefaultLoggerWriter = "stderr"
)
View Source
const (
	TRACE = iota
	DEBUG
	INFO
	WARN
	ERROR
	NONE // To entirely disable logging for the Logger

	DefaultLevel = INFO
	DefaultFlags = log.Lmsgprefix | log.Ltime | log.Ldate | log.Lshortfile
)

Variables

This section is empty.

Functions

func FindFileWithFallback

func FindFileWithFallback(dir string, file string) (*os.File, error)

Types

type Log

type Log struct {
	*log.Logger
	Level LogLevel
	Name  string
}
var RootLog *Log

RootLog is the default log, it needs to be initialized after the init() function, so that configuration (if any) can be picked up.

func NewLog

func NewLog(name string) *Log

func (*Log) Debug

func (l *Log) Debug(format string, v ...interface{})

func (*Log) Error

func (l *Log) Error(format string, v ...interface{})

func (*Log) Fatal

func (l *Log) Fatal(err error)

func (*Log) Info

func (l *Log) Info(format string, v ...interface{})

func (*Log) Trace

func (l *Log) Trace(format string, v ...interface{})

func (*Log) Warn

func (l *Log) Warn(format string, v ...interface{})

type LogConfig

type LogConfig struct {
	Loggers map[string]LoggerConfig `yaml:"loggers"`
}
var (
	// DefaultLoggerConfigurations is not really a var, but Go is not smart enough
	// to figure out it's a constant
	DefaultLoggerConfigurations           = LoggerConfig{Level: DefaultLoggerLevel, Writer: DefaultLoggerWriter}
	LoggersConfiguration        LogConfig = LogConfig{

		Loggers: map[string]LoggerConfig{
			DefaultLoggerName: DefaultLoggerConfigurations,
		},
	}
)

type LogLevel

type LogLevel = int8

func UnmarshalLevel

func UnmarshalLevel(text string) LogLevel

UnmarshalLevel converts a string to a Level. We cannot simply implement the UnmarshalText method, because `LogLevel` (`uint8`)is not considered to be "local"

type Loggable

type Loggable interface {
	SetLogLevel(level LogLevel)
}

A Loggable type is one that has a Log and exposes it to its clients

type LoggerConfig

type LoggerConfig struct {
	Level  string `yaml:"level"`
	Writer string `yaml:"writer"`
}

func GetLoggerConfig

func GetLoggerConfig(name string) LoggerConfig

GetLoggerConfig returns the configuration for the given logger; if not specified, it will return the default configuration.

Jump to

Keyboard shortcuts

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