log

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 20

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug calls Debug on the global Logger object.

func Debugf

func Debugf(format string, args ...interface{})

Debugf calls Debugf on the global Logger object.

func Debugln

func Debugln(args ...interface{})

Debugln calls Debugln on the global Logger object.

func Error

func Error(args ...interface{})

Error calls Error on the global Logger object.

func Errorf

func Errorf(format string, args ...interface{})

Errorf calls Errorf on the global Logger object.

func Errorln

func Errorln(args ...interface{})

Errorln calls Errorln on the global Logger object.

func Fatal

func Fatal(args ...interface{})

Fatal calls Fatal on the global Logger object.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf calls Fatalf on the global Logger object.

func Fatalln

func Fatalln(args ...interface{})

Fatalln calls Fatalln on the global Logger object.

func Info

func Info(args ...interface{})

Info calls Info on the global Logger object.

func Infof

func Infof(format string, args ...interface{})

Infof calls Infof on the global Logger object.

func Infoln

func Infoln(args ...interface{})

Infoln calls Infoln on the global Logger object.

func Panic

func Panic(args ...interface{})

Panic calls Panic on the global Logger object.

func Panicf

func Panicf(format string, args ...interface{})

Panicf calls Panicf on the global Logger object.

func Panicln

func Panicln(args ...interface{})

Panicln calls Panicln on the global Logger object.

func Print

func Print(args ...interface{})

Print calls Print on the global Logger object.

func Printf

func Printf(format string, args ...interface{})

Printf calls Printf on the global Logger object.

func Println

func Println(args ...interface{})

Println calls Println 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 Trace

func Trace(args ...interface{})

Trace calls Trace on the global Logger object.

func Tracef

func Tracef(format string, args ...interface{})

Tracef calls Tracef on the global Logger object.

func Traceln

func Traceln(args ...interface{})

Traceln calls Traceln on the global Logger object.

func Warn

func Warn(args ...interface{})

Warn calls Warn on the global Logger object.

func Warnf

func Warnf(format string, args ...interface{})

Warnf calls Warnf on the global Logger object.

func Warnln

func Warnln(args ...interface{})

Warnln calls Warnln 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

func MakeEmbedding(log Logger) Embedding

MakeEmbedding returns an Embedding around log.

func (Embedding) Log added in v0.4.0

func (em Embedding) Log() Logger

Log returns the embedded Logger.

func (*Embedding) SetLog added in v0.4.0

func (em *Embedding) SetLog(l Logger)

SetLog sets the embedded Logger.

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
)

func (Level) String

func (l Level) String() string

String returns the string representation.

type LevelLogger

type LevelLogger interface {
	StdLogger
	// Tracef logs a message at level Trace. Arguments are handled in the manner of fmt.Printf.
	Tracef(format string, args ...interface{})
	// Debugf logs a message at level Debug. Arguments are handled in the manner of fmt.Printf.
	Debugf(format string, args ...interface{})
	// Infof logs a message at level Info. Arguments are handled in the manner of fmt.Printf.
	Infof(format string, args ...interface{})
	// Warnf logs a message at level Warn. Arguments are handled in the manner of fmt.Printf.
	Warnf(format string, args ...interface{})
	// Errorf logs a message at level Error. Arguments are handled in the manner of fmt.Printf.
	Errorf(format string, args ...interface{})
	// Trace logs a message at level Trace.
	Trace(...interface{})
	// Debug logs a message at level Debug.
	Debug(...interface{})
	// Info logs a message at level Info.
	Info(...interface{})
	// Warn logs a message at level Warn.
	Warn(...interface{})
	// Error logs a message at level Error.
	Error(...interface{})
	// Traceln logs a message at level Trace. Arguments are handled in the manner of fmt.Println.
	Traceln(...interface{})
	// Debugln logs a message at level Debug. Arguments are handled in the manner of fmt.Println.
	Debugln(...interface{})
	// Infoln logs a message at level Info. Arguments are handled in the manner of fmt.Println.
	Infoln(...interface{})
	// Warnln logs a message at level Warn. Arguments are handled in the manner of fmt.Println.
	Warnln(...interface{})
	// Errorln logs a message at level Error. Arguments are handled in the manner of fmt.Println.
	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

func AppendField(owner Owner, key string, value interface{}) Logger

AppendField sets the given field in the owner's logger. The resulting logger is also returned.

func AppendFields added in v0.4.0

func AppendFields(owner Owner, fs Fields) Logger

AppendFields sets the given fields in the owner's logger. The resulting logger is also returned.

func Default added in v0.9.0

func Default() Logger

Default returns the currently set framework logger.

func WithError

func WithError(err error) Logger

WithError calls WithError on the global Logger object.

func WithField

func WithField(key string, value interface{}) Logger

WithField calls WithField on the global Logger object.

func WithFields

func WithFields(fs Fields) Logger

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 prints to the logger. Arguments are handled in the manner of fmt.Printf.
	Printf(format string, args ...interface{})
	// Print prints to the logger. Arguments are handled in the manner of fmt.Print.
	Print(...interface{})
	// Println prints to the logger. Arguments are handled in the manner of fmt.Println.
	Println(...interface{})
	// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
	Fatalf(format string, args ...interface{})
	// Fatal is equivalent to Print() followed by a call to os.Exit(1).
	Fatal(...interface{})
	// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
	Fatalln(...interface{})
	// Panicf is equivalent to Printf() followed by a call to panic().
	Panicf(format string, args ...interface{})
	// Panic is equivalent to Print() followed by a call to panic().
	Panic(...interface{})
	// Panicln is equivalent to Println() followed by a call to panic().
	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.

Directories

Path Synopsis
Package logrus contains an adaptation of the github.com/sirupsen/logrus project to our log interface.
Package logrus contains an adaptation of the github.com/sirupsen/logrus project to our log interface.

Jump to

Keyboard shortcuts

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