Documentation ¶
Overview ¶
Package logger allows configurable, per-package logging.
Index ¶
- Variables
- func Help()
- func HelpLevels()
- type LogLevel
- type Logger
- func (l *Logger) Add(name, help string)
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(format string, a ...interface{})
- func (l *Logger) Desperate(msg string)
- func (l *Logger) Desperatef(format string, a ...interface{})
- func (l *Logger) Enabled() bool
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(format string, a ...interface{})
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(format string, a ...interface{})
- func (l *Logger) Log(msg string)
- func (l *Logger) Logf(format string, a ...interface{})
- func (l *Logger) String() string
- func (l *Logger) Sub(name string) *Logger
- func (l *Logger) Warning(msg string)
- func (l *Logger) Warningf(format string, a ...interface{})
Constants ¶
This section is empty.
Variables ¶
var Context = func() string { return "" }
Context is a function returning a string that will be prepended to every log message, if defined. This can be used to insert timestamps, CPU info... The default does nothing and debug messages will be displayed as given.
var Enabled = make(map[string]bool)
Enabled setting controls whether logging will occur for a given module name when the usual methods are called. Default is no logging. Enabling 'all' will turn on debug output for every module.
var Level = Info // Sensible default
Level is the global log level above which nothing will be displayed.
var Levels = map[string]LogLevel{ "fatal": Fatal, "warning": Warning, "info": Info, "debug": Debug, "desperate": Desperate, }
Levels that can be specified on the command line.
var Loggers = make(map[string]*Logger)
Loggers is a registry of currently defined package-specific loggers.
Functions ¶
func Help ¶
func Help()
Help prints all registered loggers and sub-loggers so the user knows what can be enabled.
func HelpLevels ¶
func HelpLevels()
HelpLevels lists the available log levels. Hardcoded in there because the order in which we put them in the Levels mapping is not guaranteed anyway. TODO: sort levels by enum value, auto-detect default based on Level value.
Types ¶
type LogLevel ¶
type LogLevel uint8
LogLevel representing the priority of a log message. An attempt to log a message whose LogLevel is above logger.Level will be silently ignored.
type Logger ¶
type Logger struct { Name string // Package or module name for this logger Help string // Help text to be displayed when calling with -debug help // contains filtered or unexported fields }
Logger represents a name-based logger for "simple" debugging. Each package should register itself with logger, which will allow for a complete listing of all possible logger package/modules that can be used with the -debug flag.
func New ¶
New returns a Logger instance specific to the given package, after registering it with our base logger package so this logger and its modules can be listed from the command-line. Will panic if a logger with the same name is already defined.
func (*Logger) Add ¶
Add a sub-module to a package logger, which can then be enabled by using -debug <pkg>/<module> or -debug <pkg>/* on the command line.
func (*Logger) Desperatef ¶
Desperatef format-prints a message if the global log level is the maximum.
func (*Logger) Infof ¶
Infof format-prints a message if the global log level is Info (the default) or more.
func (*Logger) Sub ¶
Sub returns a sub-module with the given name. If called with a module name that hasn't been registered with Add() first, returns the main logger. Otherwise, returns a Logger instance to allow chain call to print methods.