Documentation ¶
Overview ¶
Package log implements the logger interface of go-perun. Users are expected to pass an implementation of this interface to harmonize go-perun's logging with their application logging.
It mimics the interface of logrus, which is go-perun's logger of choice It is also possible to pass a simpler logger like the standard library's log logger by converting it to a perun logger. Use the Fieldify and Levellify factories for that.
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func Set(l Logger)
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Traceln(args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- type Embedding
- type Fields
- type Level
- type LevelLogger
- type Levellified
- func (l *Levellified) Debug(args ...interface{})
- func (l *Levellified) Debugf(format string, args ...interface{})
- func (l *Levellified) Debugln(args ...interface{})
- func (l *Levellified) Error(args ...interface{})
- func (l *Levellified) Errorf(format string, args ...interface{})
- func (l *Levellified) Errorln(args ...interface{})
- func (l *Levellified) Info(args ...interface{})
- func (l *Levellified) Infof(format string, args ...interface{})
- func (l *Levellified) Infoln(args ...interface{})
- func (l *Levellified) Trace(args ...interface{})
- func (l *Levellified) Tracef(format string, args ...interface{})
- func (l *Levellified) Traceln(args ...interface{})
- func (l *Levellified) Warn(args ...interface{})
- func (l *Levellified) Warnf(format string, args ...interface{})
- func (l *Levellified) Warnln(args ...interface{})
- type Logger
- type Owner
- type StdLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf calls Debugf on the global Logger object.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf calls Errorf on the global Logger object.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf calls Fatalf on the global Logger object.
func Infof ¶
func Infof(format string, args ...interface{})
Infof calls Infof on the global Logger object.
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf calls Panicf on the global Logger object.
func Printf ¶
func Printf(format string, args ...interface{})
Printf calls Printf on the global Logger object.
func Set ¶
func Set(l Logger)
Set sets the framework logger. It is set to the none-logger by default. Set accepts nil and then sets the none-logger.
func Tracef ¶
func Tracef(format string, args ...interface{})
Tracef calls Tracef on the global Logger object.
Types ¶
type Embedding ¶ added in v0.4.0
type Embedding struct {
// contains filtered or unexported fields
}
An Embedding can be embedded into any struct to endow it with a logger and getter and setter for this logger. Embedding implements an Owner.
func MakeEmbedding ¶ added in v0.4.0
MakeEmbedding returns an Embedding around log.
type Fields ¶
type Fields map[string]interface{}
Fields is a collection of fields that can be passed to FieldLogger.WithFields.
type Level ¶
type Level int8
Level is the log level.
const ( // FatalLevel calls the wrapped logger's Fatal method with the prefix "[fatal]". // The wrapped logger should usually immediately exit the program with // os.Exit(1) or similar. It it the highest level of severity. FatalLevel Level = iota - defaultLogLevelShift // -3: default level WarnLevel // PanicLevel calls the wrapped logger's Panic method with the prefix "[panic]". // The wrapped logger should usually call panic with the given message. PanicLevel // ErrorLevel calls the wrapped logger's Print method with the prefix "[error]". ErrorLevel // WarnLevel calls the wrapped logger's Print method with the prefix "[warn]". // It is the default level. WarnLevel // InfoLevel calls the wrapped logger's Print method with the prefix "[info]". InfoLevel // DebugLevel calls the wrapped logger's Print method with the prefix "[debug]". DebugLevel // TraceLevel calls the wrapped logger's Print method with the prefix "[trace]". TraceLevel )
type LevelLogger ¶
type LevelLogger interface { StdLogger Tracef(format string, args ...interface{}) Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Trace(...interface{}) Debug(...interface{}) Info(...interface{}) Warn(...interface{}) Error(...interface{}) Traceln(...interface{}) Debugln(...interface{}) Infoln(...interface{}) Warnln(...interface{}) Errorln(...interface{}) }
LevelLogger is an extension to the StdLogger with different verbosity levels.
type Levellified ¶
type Levellified struct { // wrapped logger StdLogger // Lvl is the current logging level Lvl Level }
Levellified levellifies a standard logger. Calls are just forwarded to the wrapped logger's Print{,f,ln} methods with the prefix [level], except for levels PanicLevel and FatalLevel, which are forwarded to the respective methods.
func (*Levellified) Debug ¶
func (l *Levellified) Debug(args ...interface{})
Debug implements log level debug.
func (*Levellified) Debugf ¶
func (l *Levellified) Debugf(format string, args ...interface{})
Debugf implementents log level debug and format parameters.
func (*Levellified) Debugln ¶
func (l *Levellified) Debugln(args ...interface{})
Debugln implements log.Debugln with white spaces in between arguments.
func (*Levellified) Error ¶
func (l *Levellified) Error(args ...interface{})
Error implements log level error.
func (*Levellified) Errorf ¶
func (l *Levellified) Errorf(format string, args ...interface{})
Errorf implementents log level error and format parameters.
func (*Levellified) Errorln ¶
func (l *Levellified) Errorln(args ...interface{})
Errorln implements log.Errorln with white spaces in between arguments.
func (*Levellified) Info ¶
func (l *Levellified) Info(args ...interface{})
Info implements log level info.
func (*Levellified) Infof ¶
func (l *Levellified) Infof(format string, args ...interface{})
Infof implementents log level info and format parameters.
func (*Levellified) Infoln ¶
func (l *Levellified) Infoln(args ...interface{})
Infoln implements log.Infoln with white spaces in between arguments.
func (*Levellified) Trace ¶
func (l *Levellified) Trace(args ...interface{})
Trace implements log level trace.
func (*Levellified) Tracef ¶
func (l *Levellified) Tracef(format string, args ...interface{})
Tracef implementents log level trace and format parameters.
func (*Levellified) Traceln ¶
func (l *Levellified) Traceln(args ...interface{})
Traceln implements log.TraceLn with white spaces in between arguments.
func (*Levellified) Warn ¶
func (l *Levellified) Warn(args ...interface{})
Warn implements log level warn.
func (*Levellified) Warnf ¶
func (l *Levellified) Warnf(format string, args ...interface{})
Warnf implementents log level warn and format parameters.
func (*Levellified) Warnln ¶
func (l *Levellified) Warnln(args ...interface{})
Warnln implements log.Warnln with white spaces in between arguments.
type Logger ¶
type Logger interface { LevelLogger WithField(key string, value interface{}) Logger WithFields(Fields) Logger WithError(error) Logger }
Logger is a LevelLogger with structured field logging capabilities. This is the interface that needs to be passed to go-perun.
func AppendField ¶ added in v0.4.0
AppendField sets the given field in the owner's logger. The resulting logger is also returned.
func AppendFields ¶ added in v0.4.0
AppendFields sets the given fields in the owner's logger. The resulting logger is also returned.
func WithFields ¶
WithFields calls WithFields on the global Logger object.
type Owner ¶ added in v0.4.0
type Owner interface { // Log returns the logger used by the Owner. Log() Logger // SetLog sets the logger that the Owner uses in the future. SetLog(Logger) }
An Owner owns a Logger that can be retrieved and a new Logger can be set.
type StdLogger ¶
type StdLogger interface { Printf(format string, args ...interface{}) Print(...interface{}) Println(...interface{}) Fatalf(format string, args ...interface{}) Fatal(...interface{}) Fatalln(...interface{}) Panicf(format string, args ...interface{}) Panic(...interface{}) Panicln(...interface{}) }
StdLogger describes the interface of the standard library log package logger. It is the base for more complex loggers. A StdLogger can be converted into a LevelLogger by wrapping it with a Levellified struct.