Documentation
¶
Overview ¶
Package log defines an interface and default implementation for subsystem logging.
Log level verbosity may be modified at runtime for each individual subsystem logger.
The default implementation in this package must be created by the Backend type. Backends can write to any io.Writer, including multi-writers created by io.MultiWriter. Multi-writers allow log output to be written to many writers, standard output and log files.
Optional logging behavior can be specified by using the LOGFLAGS environment variable and overridden per-Backend by using the WithFlags call option. Multiple LOGFLAGS options can be specified, separated by commas.
The following options are recognized:
longfile: Include the full filepath and line number in all log messages shortfile: Include the filename and line number in all log messages. Overrides longfile.
Index ¶
Constants ¶
const ( // of the logging callsite, e.g. /a/b/c/main.go:123. Llongfile uint32 = 1 << iota // of the logging callsite, e.g. main.go:123. Overrides Llongfile. Lshortfile )
Flags to modify Backend's behavior.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
func NewBackend ¶
func NewBackend( w io.Writer, opts ...BackendOption) *Backend
NewBackend creates a logger backend from a Writer.
type BackendOption ¶
type BackendOption func(b *Backend)
func WithFlags ¶
func WithFlags( flags uint32) BackendOption
WithFlags configures a Backend to use the specified flags rather than using the package's defaults as determined through the LOGFLAGS environment variable.
type Level ¶
type Level uint32
Level constants.
func LevelFromString ¶
LevelFromString returns a level based on the input string s. If the input can't be interpreted as a valid log level, the info level and false is returned.
type Logger ¶
type Logger interface { // to log with LevelTrace. Tracef(format string, params ...interface{}) // log with LevelDebug. Debugf(format string, params ...interface{}) // log with LevelInfo. Infof(format string, params ...interface{}) // to log with LevelWarn. Warnf(format string, params ...interface{}) // to log with LevelError. Errorf(format string, params ...interface{}) // log with LevelCritical. Criticalf(format string, params ...interface{}) // and writes to log with LevelTrace. Trace(v ...interface{}) // and writes to log with LevelDebug. Debug(v ...interface{}) // and writes to log with LevelInfo. Info(v ...interface{}) // and writes to log with LevelWarn. Warn(v ...interface{}) // and writes to log with LevelError. Error(v ...interface{}) // and writes to log with LevelCritical. Critical(v ...interface{}) // Level returns the current logging level. Level() Level // SetLevel changes the logging level to the passed level. SetLevel(level Level) }
var Disabled Logger
Disabled is a Logger that will never output anything.