Documentation
¶
Overview ¶
Package kuttilog implements a simple levelled logging system. The SetLevel function sets the current level. The Print, Printf and Println functions all take a level parameter, and only log if it is less than or equal to the current level.
The package provides a Logger interface, so that the actual output can vary between implementations. The SetLogger method can be called with an appropriate implementation. There is a default implementation, which uses a standard output logger created using the Go standard log package.
Levels begin at 0, and can go up to a implementation-specific maximum. The default logger provides five levels: Quiet(0), Minimal(1), Info(2), Verbose(3) and Debug(4). The default level is Info(2).
There is also a special level: Error(-1), deliberately kept below the minimum level. All implementations must ensure that logs at this level have to mandatorily produce output.
Index ¶
Constants ¶
const ( Error = -1 Quiet = 0 Minimal = 1 Info = 2 Verbose = 3 Debug = 4 )
Default Log levels
Variables ¶
This section is empty.
Functions ¶
func MaxLevel ¶
func MaxLevel() int
MaxLevel returns the highest level permitted by the current logger.
func Print ¶
func Print(level int, v ...interface{})
Print prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Print.
func Printf ¶
Printf prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Printf.
func Println ¶
func Println(level int, v ...interface{})
Println prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Println.
func SetLogLevel ¶ added in v0.2.0
func SetLogLevel(newlevel int)
SetLogLevel sets the current log level. If level is below 0 or greater than MaxLevel, it is not changed.
Types ¶
type Logger ¶
type Logger interface {
// MaxLevel returns the maximum level permitted by this logger.
MaxLevel() int
// LevelPrefix returns rhe logger-supplied prefix string for a
// level. It may return an empty string.
LevelPrefix(level int) string
// Print prints to the log.
// Arguments are handled in the manner of fmt.Print.
Print(v ...interface{})
// Printf prints to the log.
// Arguments are handled in the manner of fmt.Printf.
Printf(format string, v ...interface{})
// Println prints to the log.
// Arguments are handled in the manner of fmt.Println.
Println(v ...interface{})
}
Logger contains methods for implementation-specific logging. Exact destination, formatting etc. is implementation-specific. Kuttilog will call each print method only if needed. It will also append a level prefix string as the first item output. Implementations can provide their own prefix strings via the LevelPrefix method.