logger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: BSD-3-Clause Imports: 0 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fields

type Fields map[string]interface{}

Fields defines a map of fields to be passed to WithFields()

type Level

type Level uint32
const (
	// Fatal level. Logs and then calls `os.Exit(1)`. It should execute
	// regardless of the set logging level.
	Fatal Level = 0
	// Panic level, highest level of severity. Logs and then calls
	// panic with the message passed to enable recovery.
	Panic Level = 10
	// Error level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	Error Level = 20
	// Warn level. Non-critical entries that deserve eyes.
	Warn Level = 30
	// Info level. General operational entries about what's going on inside the
	// application.
	Info Level = 40
	// Debug level. Usually only enabled when debugging. Very verbose logging.
	Debug Level = 50
	// Trace level. Usually only enabled when debugging. Extremely verbose logging, generally including a full stack trace.
	Trace Level = 60
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `New()`.

type Logger

type Logger interface {
	// WithFields adds a map of key/value data to the log entry.
	WithFields(Fields)

	// SetLevel sets the log level of this logger. Accepts any unsigned
	// integer.
	SetLevel(level Level)

	// Fatal methods should call os.Exit() with a non-zero exit status.
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Fatalln(args ...interface{})

	// Level 1
	// Panic methods should end with a call to the panic() builtin to
	// allow recovery, regardless of log level, but should not attempt to
	// write to any logs independent of that if the log level is below
	// PanicLevel.
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Panicln(args ...interface{})

	// Level 2
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Errorln(args ...interface{})

	// Level 3
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Warnln(args ...interface{})

	// Level 4
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Infoln(args ...interface{})
	// pkg/log compatiblity, alias to Info* methods.
	Print(args ...interface{})
	Printf(format string, args ...interface{})
	Println(args ...interface{})

	// Level 5
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Debugln(args ...interface{})
}

Logger defines a common logger interface for packages that accept an injected logger. It fully implements the standard 'pkg/log' log package logging methods as well Info, Warn, Error, and Debug level equivalents. The Info* methods are expected to mirror the Print* methods.

Packages that implement this interface should support level codes and expect usage as follows:

  • Panic, highest level of severity. Log and then call panic.
  • Fatal, log and then call `os.Exit(<code>)` with a non-zero value.
  • Error, used for errors that should definitely be noted and addressed.
  • Warn, non-critical information about undesirable behavior that needs to be addressed in some way.
  • Info, general operational information about what's happening inside an application. 'Print' methods should output Info-level information.
  • Debug, usually only enabled when debugging. Add anything useful, but still exclude PII or sensitive data...

Each level should include all the log levels above it. To manage the output, this interface also implements a SetLevel(level uint) method that defines the log level of this logger.

Compatible logger packages include:

  • "github.com/bdlm/log"
  • "github.com/sirupsen/logrus"

Jump to

Keyboard shortcuts

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