Documentation
¶
Overview ¶
Package log provides global output control across the whole application. Logging comes in four levels: Silent, Major, Minor and Debug which each level more detailed than the previous. It's up to the application to decided which output belong with which level. Levels are inclusive, so, e.g., if MinorLevel is set that implies MajorLevel logging.
In general an application should have *all* output go via the logging interface once it has completed successful parsing on the command line. One exception might be start-up/shut-down messages, just in case logging is not working or has been redirected to a null consumer.
The Print and Printf interface are similar to the fmt versions with a few subtle differences due to the need to prefix lines. The main difference is that if the resulting string contains multiple lines they are all printed with the prefix for the logging level. The second different is that a trailing newline is not needed and excess ones are trimmed.
Specialist logging functions external to this package should still use log.Out() to access the current io.Writer for the purposes of capturing output for tests.
Index ¶
- Constants
- func Debug(a ...interface{}) (n int, err error)
- func Debugf(format string, a ...interface{}) (n int, err error)
- func IfDebug() bool
- func IfMajor() bool
- func IfMinor() bool
- func Level() logLevel
- func Major(a ...interface{}) (n int, err error)
- func Majorf(format string, a ...interface{}) (n int, err error)
- func Minor(a ...interface{}) (n int, err error)
- func Minorf(format string, a ...interface{}) (n int, err error)
- func Out() io.Writer
- func SetLevel(l logLevel)
- func SetOut(w io.Writer)
Constants ¶
const ( SilentLevel logLevel = iota MajorLevel MinorLevel DebugLevel )
Define the valid logLevels which can be set with SetLevel()
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
Debug provides a fmt.Print like interface to logging. Output is only generated if the level is >= Debug. Debug uses fmt.Sprint to generate the output line thus it inherits the feature whereby spaces are added between operands when neither is a string.
func Debugf ¶
Debugf provides a fmt.Printf equivalent interface to logging. Output is only generated if the level is >= Debug.
func IfDebug ¶
func IfDebug() bool
IfDebug returns true if Debug, Minor or Major logging is enabled.
func IfMajor ¶
func IfMajor() bool
IfMajor returns true if Major logging is enabled. Applications have access to these If* functions in cases where evaluation of the log arguments is expensive and the caller wishes to minimize that cost.
func Major ¶
Major provides a fmt.Print like interface to logging. Output is only generated if the level is >= Major. Major uses fmt.Sprint to generate the output line thus it inherits the feature whereby spaces are added between operands when neither is a string.
func Majorf ¶
Majorf provides an approximate fmt.Printf equivalent interface to logging. Output is only generated if the level is >= Major. A newline is always added to the end of the output so the caller should not have that in there string. All output is prefixed with the current major prefix which may be an empty string.
func Minor ¶
Minor provides a fmt.Print like interface to logging. Output is only generated if the level is >= Minor. Minor uses fmt.Sprint to generate the output line thus it inherits the feature whereby spaces are added between operands when neither is a string.
func Minorf ¶
Minorf provides a fmt.Printf equivalent interface to logging. Output is only generated if the level is >= Minor.
func Out ¶
Out returns the current io.Writer for specialist logger functions which are not controlled by log levels. The return value will never be nil.
Types ¶
This section is empty.