log

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: MPL-2.0 Imports: 6 Imported by: 6

Documentation

Overview

Package log extends the capabilities of the Golang stdlib "log" package.

It defines a type, LevelLogger, which embeds the log.Logger type. This allows all of the exported log.Logger functions to be exported for the LevelLogger.

Like the log package, this package exports logger helper functions (Print[f|ln], Fatal[f|ln], Panic[f|ln]) through a standard logger. In this way, developers can import the logger and utilize the logging functionality without creating a LevelLogger reference.

This package adds the concept of log levels to the standard logger. This is exposed through the exported 'LogLevel' type. The logger will filter out log messages based on the log level- only displaying messages that are of the logger's level or higher. LevelLogger also tags each log message with the LogLevel as a prefix.

This package exports a Printf-style function for each of the defined LogLevels - Debugf, Tracef, Infof, Warningf, and Errorf.

This package defines the following log levels (from most verbose to least verbose):

LevelDebug - Intermediate values, calculations
LevelTrace - Function enter/exit notifications
LevelInfo - Informational messages, not used in debugging or runtime
LevelWarning - Errors; The system could recover gracefully
LevelError - Errors; The system could not recover gracefully
LevelNone - Suppresses all log output, no messages commited to output

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

func Debugf(format string, a ...interface{})

Debugf writes a debug message using the standard logger.

See LevelLogger.Debugf()

func Errorf

func Errorf(format string, a ...interface{})

Errorf writes an error message using the standard logger.

See LevelLogger.Errorf()

func Fatal

func Fatal(a ...interface{})

Fatal

See 'pkg/log#Fatal()'

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf

See 'pkg/log#Fatalf()'

func Fatalln

func Fatalln(a ...interface{})

Fatalln

See 'pkg/log#Fatalln()'

func Flags

func Flags() int

Flags retrieves the flags of the standard logger

See 'pkg/log#Flags()'

func Infof

func Infof(format string, a ...interface{})

Infof writes an info message using the standard logger.

See LevelLogger.Infof()

func Panic

func Panic(a ...interface{})

Panic

See 'pkg/log#Panic()'

func Panicf

func Panicf(format string, a ...interface{})

Panicf

See 'pkg/log#Panicf()'

func Panicln

func Panicln(a ...interface{})

Panicln

See 'pkg/log#Panicln()'

func Prefix

func Prefix() string

Prefix retrieves the prefix of the standard logger

See 'pkg/log#Prefix()'

func Print

func Print(a ...interface{})

Print

See 'pkg/log#Print()'

func Printf

func Printf(format string, a ...interface{})

Printf

See 'pkg/log#Printf()'

func Println

func Println(a ...interface{})

Println

See 'pkg/log#Println()'

func SetFlags

func SetFlags(flags int)

SetFlags sets the flags of the standard logger

See 'pkg/log#SetFlags()'

func SetLevel

func SetLevel(level LogLevel)

SetLevel sets the LogLevel for the package-wide standard logger. The LogLevel should be a 'LogLevel' constant.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output of the standard logger

See 'pkg/log#SetOutput()'

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the prefix of the standard logger

See 'pkg/log#SetPrefix()'

func Tracef

func Tracef(format string, a ...interface{})

Tracef writes a trace message using the standard logger.

See LevelLogger.Tracef()

func Warningf

func Warningf(format string, a ...interface{})

Warningf writes a warning message using the standard logger.

See LevelLogger.Warningf()

Types

type LevelLogger

type LevelLogger struct {
	// Embedded Logger from 'pkg/log'.  This allows the level logger to
	// intercept all of the functionality of the Go stdlib logger package
	// and let us embed our own behavior.
	*log.Logger
	// contains filtered or unexported fields
}

LevelLogger extends the Logger type from the log package with the addition of log levels and level-based logging methods.

func NewLevelLogger

func NewLevelLogger(out io.Writer, flags int, logLevel LogLevel) *LevelLogger

NewLeveLogger creates a new reference to a 'LevelLogger' with the provided output writer, logging flags, and log level threshold.

func (*LevelLogger) Debugf

func (logger *LevelLogger) Debugf(format string, a ...interface{})

Debugf writes a debug message to the logs. The message will only be written if the logger's level is less than or equal to LevelDebug.

Debug messages can include intermediate values and calculations for stepping through the program.

func (*LevelLogger) Errorf

func (logger *LevelLogger) Errorf(format string, a ...interface{})

Errorf writes an error message to the logs. The message will only be written if the logger's level is less than or equal to LevelError.

func (*LevelLogger) Fatal

func (logger *LevelLogger) Fatal(a ...interface{})

Fatal writes a fatal message to the log using custom fatal prefix

See 'pkg/log#Logger.Fatal()'

func (*LevelLogger) Fatalf

func (logger *LevelLogger) Fatalf(format string, a ...interface{})

Fatalf writes a fatal message to the log using custom fatal prefix

See 'pkg/log#Logger.Fatalf()'

func (*LevelLogger) Fatalln

func (logger *LevelLogger) Fatalln(a ...interface{})

Fataln writes a fatal message to the log using custom fatal prefix

See 'pkg/log#Logger.Fatalln()'

func (*LevelLogger) Infof

func (logger *LevelLogger) Infof(format string, a ...interface{})

Infof writes an info message to the logs. The message will only be written if the logger's level is less than or equal to LevelInfo.

Info messages are important system messages that do not require further action or communicate any type of error.

func (*LevelLogger) Level

func (logger *LevelLogger) Level() LogLevel

Level returns the LogLevel of the logger

func (*LevelLogger) Panic

func (logger *LevelLogger) Panic(a ...interface{})

Panic writes a panic message to the log using custom panic prefix

See 'pkg/log#Logger.Panic()'

func (*LevelLogger) Panicf

func (logger *LevelLogger) Panicf(format string, a ...interface{})

Panicf writes a panic message to the log using custom panic prefix

See 'pkg/log#Logger.Panicf()'

func (*LevelLogger) Panicln

func (logger *LevelLogger) Panicln(a ...interface{})

Panicln writes a panic message to the log using custom panic prefix

See 'pkg/log#Logger.Panicln()'

func (*LevelLogger) SetLevel

func (logger *LevelLogger) SetLevel(level LogLevel)

SetLevel sets the underlying LogLevel for the LevelLogger. The LogLevel should be a 'LogLevel' constant.

func (*LevelLogger) Tracef

func (logger *LevelLogger) Tracef(format string, a ...interface{})

Tracef writes a trace message to the logs. The message will only be written if the logger's level is less than or equal to LevelTrace.

Trace messages are used to log the flow of execution of the application such as function enter/exit notifications.

func (*LevelLogger) Warningf

func (logger *LevelLogger) Warningf(format string, a ...interface{})

Warningf writes a warning message to the logs. The message will only be written if the logger's level is less than or equal to LevelWarning.

Warning messages are not as critical as an error and are used to communicate unsafe or potentially hazardous behavior that can be avoided or recovered.

type LogLevel

type LogLevel int

LogLevel type definition - see LogLevel constants defined below for more information.

const (
	LevelDebug LogLevel = iota
	LevelTrace
	LevelInfo
	LevelWarning
	LevelError
	LevelNone
)

Logging levels (ordered from most verbose, to least verbose). Once a logger's level is set, messages with a log level greater than or equal to the logger's level are shown. Otherwise, they are ignored.

For example, if the logger's log level is set to 'LevelWarning', only warning (LevelWarning) and error (LevelError) messages are shown. The rest are discarded. Therefore, if a logger is set to 'LevelNone', *all* log messages are discarded - including errors.

const LevelInvalid LogLevel = -1

func Level

func Level() LogLevel

Level returns the LogLevel for the package-wide standard logger

func LogLevelFromString

func LogLevelFromString(name string) (LogLevel, error)

LogLevelFromStrings converts the given the string representation of the LogLevel, return the LogLevel. If an invalid string representation is provided, an error is returned and the LogLevel return corresponds to an invalid LogLevel.

func (LogLevel) String

func (l LogLevel) String() string

String - Implements the Stringer interface. Given a log level, return the string representation. If an invalid LogLevel is provided, an empty string is returned.

Jump to

Keyboard shortcuts

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