log

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2023 License: BSD-2-Clause Imports: 4 Imported by: 0

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

View Source
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

func Debug(a ...interface{}) (n int, err error)

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

func Debugf(format string, a ...interface{}) (n int, err error)

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 IfMinor

func IfMinor() bool

IfMinor returns true if Minor or Major logging is enabled.

func Level

func Level() logLevel

Level returns current level

func Major

func Major(a ...interface{}) (n int, err error)

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

func Majorf(format string, a ...interface{}) (n int, err error)

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

func Minor(a ...interface{}) (n int, err error)

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

func Minorf(format string, a ...interface{}) (n int, err error)

Minorf provides a fmt.Printf equivalent interface to logging. Output is only generated if the level is >= Minor.

func Out

func Out() io.Writer

Out returns the current io.Writer for specialist logger functions which are not controlled by log levels. The return value will never be nil.

func SetLevel

func SetLevel(l logLevel)

SetLevel sets the current logging level. Ignored if previously set by ENV variable.

func SetOut

func SetOut(w io.Writer)

SetOut changes the output of logging to the supplied io.Writer. The default is os.Stdout. The supplied io.Writer must never be nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址