Documentation ¶
Overview ¶
Package simplelog provides a dead simple logging system.
Index ¶
Constants ¶
const ( LevelDebug int = iota // Threshold for Debug log level LevelInfo // Threshold for Info log level LevelWarning // Threshold for Warning log level LevelError // Threshold for Error log level LevelFatal // Threshold for Fatal log level (will crash the program when used) )
Constants for the different log levels supported by the library
Variables ¶
var ( Fatal = &LogLevel{prefix: "FATAL: ", level: LevelFatal, destination: os.Stderr} Error = &LogLevel{prefix: "ERROR: ", level: LevelError, destination: os.Stderr} Warning = &LogLevel{prefix: "WARNING: ", level: LevelWarning, destination: os.Stderr} Info = &LogLevel{prefix: "INFO: ", level: LevelInfo, destination: os.Stdout} Debug = &LogLevel{prefix: "DEBUG: ", level: LevelDebug, destination: os.Stdout} )
Logger objects that will be used to perform the actual logging. Each of them represents a different logging level and can be pointed to a different backend (file, stdout, etc...) TODO: Allow for a method to change log destination of a logging level (and potentially of all log levels)
var (
ErrInvalidThreshold = errors.New("Invalid Threshold. Need one between LevelDebug and LevelFatal") // When an invalid threshold has been defined
)
Common errors that can be returned
Functions ¶
func IsDebug ¶
func IsDebug() bool
IsDebug will return true if logging threshold is currently set at Debug level
func SetThreshold ¶
SetThreshold sets the logging threshold level. Will return InvalidThreshold if new threshold isn't in the accepted range
Types ¶
type LogLevel ¶
type LogLevel struct {
// contains filtered or unexported fields
}
LogLevel represents a logger object for a given log level.
func (*LogLevel) Printf ¶
Printf will use the logger attached to this LogLevel to write a log message. Message will only get written if current log level allows it (it won't write INFO messages if we're at ERROR) When writing to the Fatal log level the program will automatically exit with status code 1 TODO: Prepend the name of the application doing the logging to the msg (if it has been defined)
func (*LogLevel) Println ¶
func (l *LogLevel) Println(v ...interface{})
Println will use the logger attached to this LogLevel to write a log message. Message will only get written if current log level allows it (it won't write INFO messages if we're at ERROR) When writing to the Fatal log level the program will automatically exit with status code 1 TODO: Prepend the name of the application doing the logging to the msg (if it has been defined)