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 ¶
- func Debugf(format string, a ...interface{})
- func Errorf(format string, a ...interface{})
- func Fatal(a ...interface{})
- func Fatalf(format string, a ...interface{})
- func Fatalln(a ...interface{})
- func Flags() int
- func Infof(format string, a ...interface{})
- func Panic(a ...interface{})
- func Panicf(format string, a ...interface{})
- func Panicln(a ...interface{})
- func Prefix() string
- func Print(a ...interface{})
- func Printf(format string, a ...interface{})
- func Println(a ...interface{})
- func SetFlags(flags int)
- func SetLevel(level LogLevel)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- func Tracef(format string, a ...interface{})
- func Warningf(format string, a ...interface{})
- type LevelLogger
- func (logger *LevelLogger) Debugf(format string, a ...interface{})
- func (logger *LevelLogger) Errorf(format string, a ...interface{})
- func (logger *LevelLogger) Fatal(a ...interface{})
- func (logger *LevelLogger) Fatalf(format string, a ...interface{})
- func (logger *LevelLogger) Fatalln(a ...interface{})
- func (logger *LevelLogger) Infof(format string, a ...interface{})
- func (logger *LevelLogger) Level() LogLevel
- func (logger *LevelLogger) Panic(a ...interface{})
- func (logger *LevelLogger) Panicf(format string, a ...interface{})
- func (logger *LevelLogger) Panicln(a ...interface{})
- func (logger *LevelLogger) SetLevel(level LogLevel)
- func (logger *LevelLogger) Tracef(format string, a ...interface{})
- func (logger *LevelLogger) Warningf(format string, a ...interface{})
- type LogLevel
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 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 Prefix ¶
func Prefix() string
Prefix retrieves the prefix of the standard logger
See 'pkg/log#Prefix()'
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 SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the prefix of the standard logger
See 'pkg/log#SetPrefix()'
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.
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 LogLevelFromString ¶
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.