Documentation
¶
Overview ¶
Package log provides functions for logging debug, informational, warning, and error messages to standard output/error. Clients should set the current log level; only messages at that level or higher will actually be logged. Compared to Go's standard log package, this package supports colored output.
Inspired by https://github.com/cloudflare/cfssl/blob/master/log/log.go
Index ¶
- Variables
- func Debug(v ...interface{}) error
- func Debugf(format string, v ...interface{}) error
- func Error(v ...interface{}) error
- func Errorf(format string, v ...interface{}) error
- func Info(v ...interface{}) error
- func Infof(format string, v ...interface{}) error
- func SetLevel(l Level)
- func Warn(v ...interface{}) error
- func Warnf(format string, v ...interface{}) error
- type Level
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var UseColor = true
UseColor, if true, enables colorized output.
Functions ¶
func Debug ¶
func Debug(v ...interface{}) error
Debug logs a debug message to stdout.
Example ¶
Debug("some debug message")
Output: DEBUG: some debug message
func Debugf ¶ added in v0.3.0
Debugf logs a formatted debug message to stdout.
Example ¶
s := "debug"
Debugf("some %s message", s)
Output: DEBUG: some debug message
func Error ¶
func Error(v ...interface{}) error
Error logs an error message to stderr.
Example ¶
os.Stderr = os.Stdout
Error("some error message")
Output: ERROR: some error message
func Errorf ¶ added in v0.3.0
Errorf logs a formatted error message to stderr.
Example ¶
os.Stderr = os.Stdout
s := "error"
Errorf("some %s message", s)
Output: ERROR: some error message
func Info ¶
func Info(v ...interface{}) error
Info logs an informational message to stdout.
Example ¶
Info("some info message")
Output: INFO: some info message
func Infof ¶ added in v0.3.0
Infof logs a formatted informational message to stdout.
Example ¶
s := "info"
Infof("some %s message", s)
Output: INFO: some info message
func SetLevel ¶ added in v0.3.0
func SetLevel(l Level)
SetLevel changes the current log level to l.
Example ¶
defer SetLevel(LevelDebug)
SetLevel(LevelInfo)
Debug("some debug message")
Info("some info message")
Warn("some warning message")
Output: INFO: some info message WARNING: some warning message