Documentation ¶
Overview ¶
Package log contains logging helpers.
EXPERIMENTAL! This may change prior to the final release of this version!
This package provides syslog-style logging messages. See `log/syslog` in Go's documentation. A notable difference, though, is that this also provides formatter variants for all of the log levels.
This uses the Context.Log* functions beneath the hood, so any logger configuration for that will also hold true for this.
Example ¶
_, _, c := cookoo.Cookoo() // Set logging to go to Stdout. c.AddLogger("stdout", os.Stdout) // Set the log level to any of the Log* constants. Level = LogInfo // Functions are named as they are in log/syslog. Err(c, "Failed to do something.") // There are also formatting versions of every log function. Infof(c, "Informational message with %s.", "formatting") // Shorthand for if Level >= LogDebug if Debugging() { Debug(c, "This is a debug message.") } // You can test for any level. if Level >= LogWarning { Warn(c, "And this is a warning.") } Stack(c, "Stack trace from here.")
Output:
Index ¶
- Constants
- Variables
- func Alert(c cookoo.Context, args ...interface{})
- func Alertf(c cookoo.Context, msg string, args ...interface{})
- func Crit(c cookoo.Context, args ...interface{})
- func Critf(c cookoo.Context, msg string, args ...interface{})
- func Debug(c cookoo.Context, args ...interface{})
- func Debugf(c cookoo.Context, msg string, args ...interface{})
- func Debugging() bool
- func Emerg(c cookoo.Context, args ...interface{})
- func Emergf(c cookoo.Context, msg string, args ...interface{})
- func Err(c cookoo.Context, args ...interface{})
- func Errf(c cookoo.Context, msg string, args ...interface{})
- func Info(c cookoo.Context, args ...interface{})
- func Infof(c cookoo.Context, msg string, args ...interface{})
- func Notice(c cookoo.Context, args ...interface{})
- func Noticef(c cookoo.Context, msg string, args ...interface{})
- func Stack(c cookoo.Context, msg string)
- func Warn(c cookoo.Context, args ...interface{})
- func Warnf(c cookoo.Context, msg string, args ...interface{})
- type LogLevel
Examples ¶
Constants ¶
const ( LabelEmerg = "[emergency] " LabelAlert = "[alert] " LabelCrit = "[critical] " LabelErr = "[error] " LabelWarning = "[warning] " LabelNotice = "[notice] " LabelInfo = "[info] " LabelDebug = "[debug] " )
Labels for log levels.
Variables ¶
var Label = [8]string{ LabelEmerg, LabelAlert, LabelCrit, LabelErr, LabelWarning, LabelNotice, LabelInfo, LabelDebug, }
Functions ¶
func Debugging ¶
func Debugging() bool
Debugging returns true if the level is set to allow debugging.
Whether or not the log message is sent to the underlying logger is determined based on the Level. However, using checks like this can prevent doing costly debug computations just for the sake of logging.
if Debugging() { // Do something expensive. costlyOperation() Debug(c, "msg") }
Otherwise, this will write the message to the lower-level logger, which can then decide (presumably based on Level) what to do with the message.