logger

package
v0.0.0-...-7ee7fde Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Llongfile modifies the logger output to include full path and line number
	// of the logging callsite, e.g. /a/b/c/main.go:123.
	Llongfile uint32 = 1 << iota

	// Lshortfile modifies the logger output to include filename and line number
	// of the logging callsite, e.g. main.go:123.  Overrides Llongfile.
	Lshortfile
)

Flags to modify Backend's behavior.

Variables

This section is empty.

Functions

func CloseLogRotator

func CloseLogRotator()

CloseLogRotator closes the log rotator if it has been created

func InitLogRotator

func InitLogRotator(logFile string)

initLogRotator initializes the logging rotater to write logs to logFile and create roll files in the same directory. It must be called before the package-global log rotater variables are used.

func SetLogLevel

func SetLogLevel(subsystemID string, logLevel string) bool

setLogLevel sets the logging level for provided subsystem. Invalid subsystems are ignored. Uninitialized subsystems are dynamically created as needed.

func SetLogLevels

func SetLogLevels(logLevel string)

setLogLevels sets the logger level for all subsystem loggers to the passed level. It also dynamically creates the subsystem loggers as needed, so it can be used to initialize the logging system.

func SupportedSubsystems

func SupportedSubsystems() []string

SupportedSubsystems returns a sorted slice of the supported subsystems for logging purposes.

func ValidLogLevel

func ValidLogLevel(logLevel string) bool

validLogLevel returns whether or not logLevel is a valid debug logger level.

Types

type Backend

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

Backend is a logging backend. Subsystems created from the backend write to the backend's Writer. Backend provides atomic writes to the Writer from all subsystems.

func NewBackend

func NewBackend(w io.Writer, opts ...BackendOption) *Backend

NewBackend creates a logger backend from a Writer.

func (*Backend) Logger

func (b *Backend) Logger(subsystemTag string) Logger

Logger returns a new logger for a particular subsystem that writes to the Backend b. A tag describes the subsystem and is included in all logger messages. The logger uses the info verbosity level by default.

type BackendOption

type BackendOption func(b *Backend)

BackendOption is a function used to modify the behavior of a Backend.

func WithFlags

func WithFlags(flags uint32) BackendOption

WithFlags configures a Backend to use the specified flags rather than using the package's defaults as determined through the LOGFLAGS environment variable.

type Level

type Level uint32

Level is the level at which a logger is configured. All messages sent to a level which is below the current level are filtered.

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelCritical
	LevelOff
)

Level constants.

func LevelFromString

func LevelFromString(s string) (l Level, ok bool)

LevelFromString returns a level based on the input string s. If the input can't be interpreted as a valid logger level, the info level and false is returned.

func (Level) String

func (l Level) String() string

String returns the tag of the logger used in logger messages, or "OFF" if the level will not produce any logger output.

type Logger

type Logger interface {
	// Tracef formats message according to format specifier and writes to
	// to logger with LevelTrace.
	Tracef(format string, params ...interface{})

	// Debugf formats message according to format specifier and writes to
	// logger with LevelDebug.
	Debugf(format string, params ...interface{})

	// Infof formats message according to format specifier and writes to
	// logger with LevelInfo.
	Infof(format string, params ...interface{})

	// Warnf formats message according to format specifier and writes to
	// to logger with LevelWarn.
	Warnf(format string, params ...interface{})

	// Errorf formats message according to format specifier and writes to
	// to logger with LevelError.
	Errorf(format string, params ...interface{})

	// Criticalf formats message according to format specifier and writes to
	// logger with LevelCritical.
	Criticalf(format string, params ...interface{})

	// Trace formats message using the default formats for its operands
	// and writes to logger with LevelTrace.
	Trace(v ...interface{})

	// Debug formats message using the default formats for its operands
	// and writes to logger with LevelDebug.
	Debug(v ...interface{})

	// Info formats message using the default formats for its operands
	// and writes to logger with LevelInfo.
	Info(v ...interface{})

	// Warn formats message using the default formats for its operands
	// and writes to logger with LevelWarn.
	Warn(v ...interface{})

	// Error formats message using the default formats for its operands
	// and writes to logger with LevelError.
	Error(v ...interface{})

	// Critical formats message using the default formats for its operands
	// and writes to logger with LevelCritical.
	Critical(v ...interface{})

	// Level returns the current logging level.
	Level() Level

	// SetLevel changes the logging level to the passed level.
	SetLevel(level Level)
}

Logger is an interface which describes a level-based logger. A default implementation of Logger is implemented by this package and can be created by calling (*Backend).Logger.

var Disabled Logger

Disabled is a Logger that will never output anything.

func GetLog

func GetLog() Logger

func GetLogger

func GetLogger(name string) Logger

Jump to

Keyboard shortcuts

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