logging

package module
v0.0.0-...-d99b607 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 5 Imported by: 0

README

Logging

Documentation

Overview

Package logging implements a logging based on RFC5424 standards, simliar to syslog and PHP's PSR-3. This is beneficial for teams already using RFC5424 or PSR-3 as part of their logging practices for things such as PHP services. You can read more about RFC5424 at https://tools.ietf.org/html/rfc5424/ and PSR-3 at https://www.php-fig.org/psr/psr-3/.

Index

Constants

View Source
const (
	// Emergency denotes the system is unusable.
	Emergency = iota
	// Alert denotes action must be taken immediately.
	Alert
	// Critical denotes critical conditions.
	Critical
	// Error denotes error conditions.
	Error
	// Warning denotes warning conditions.
	Warning
	// Notice denotes normal but significant condition.
	Notice
	// Informational denotes informational messages.
	Informational
	// Debug denotes debug-level messages.
	Debug
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Level defines the severity of the message provided to the Logger.

type Logger

type Logger interface {
	// Emergency denotes the system is unusable. Usage should accompany
	// instances that cause a restart or program exit. A Logger itself should
	// never panic or exit as part of a call to Emergency. The callee is
	// responsible to manage program exit.
	Emergency(msg string, context ...string) error
	// Alert denotes action must be taken immediately.
	Alert(msg string, context ...string) error
	// Critical denotes critical conditions.
	Critical(msg string, context ...string) error
	// Error denotes error conditions.
	Error(msg string, context ...string) error
	// Warning denotes warning conditions.
	Warning(msg string, context ...string) error
	// Notice denotes normal but significant condition.
	Notice(msg string, context ...string) error
	// Informational denotes informational messages.
	Informational(msg string, context ...string) error
	// Debug denotes debug-level messages.
	Debug(msg string, context ...string) error
	// Log provides logging based on the passed log Level. When defining a
	// custom Logger, it is recommended to implement a robust Log function and
	// then call this function within other log functions such as Error.
	Log(level Level, msg string, context ...string) error
}

Logger provides a standard set of logging functions. If you are looking to implement your own Logger, the StdoutLogger implementation is a good example.

func NewLogger

func NewLogger(loggers ...Logger) Logger

NewLogger returns a singluar Logger instance that will distribute logs to all of the Loggers provided as arguments. If no arguments are provided, the StdoutLogger will be used as a default. Here is an example of creating a logger with multiple destinations.

logger := NewLogger(NewStdoutLogger(), NewPapertrailLogger(ptConfig))

type NilLogger

type NilLogger struct{}

NilLogger doesn't do anything.

func NewNilLogger

func NewNilLogger() *NilLogger

NewNilLogger creates a new instance of the NilLogger, which is useful for testing objects that require a Logger.

func (*NilLogger) Alert

func (logger *NilLogger) Alert(msg string, context ...string) error

func (*NilLogger) Critical

func (logger *NilLogger) Critical(msg string, context ...string) error

func (*NilLogger) Debug

func (logger *NilLogger) Debug(msg string, context ...string) error

func (*NilLogger) Emergency

func (logger *NilLogger) Emergency(msg string, context ...string) error

func (*NilLogger) Error

func (logger *NilLogger) Error(msg string, context ...string) error

func (*NilLogger) Informational

func (logger *NilLogger) Informational(msg string, context ...string) error

func (*NilLogger) Log

func (logger *NilLogger) Log(level Level, msg string, context ...string) error

func (*NilLogger) Notice

func (logger *NilLogger) Notice(msg string, context ...string) error

func (*NilLogger) Warning

func (logger *NilLogger) Warning(msg string, context ...string) error

type StdoutLogger

type StdoutLogger struct {
	// contains filtered or unexported fields
}

StdoutLogger is the default Logger implementation. It will take messages and send them to os.stdout.

func NewStdoutLogger

func NewStdoutLogger() *StdoutLogger

NewStdoutLogger creates a new instance of the StdoutLogger.

func (*StdoutLogger) Alert

func (logger *StdoutLogger) Alert(msg string, context ...string) error

func (*StdoutLogger) Critical

func (logger *StdoutLogger) Critical(msg string, context ...string) error

func (*StdoutLogger) Debug

func (logger *StdoutLogger) Debug(msg string, context ...string) error

func (*StdoutLogger) Emergency

func (logger *StdoutLogger) Emergency(msg string, context ...string) error

func (*StdoutLogger) Error

func (logger *StdoutLogger) Error(msg string, context ...string) error

func (*StdoutLogger) Informational

func (logger *StdoutLogger) Informational(msg string, context ...string) error

func (*StdoutLogger) Log

func (logger *StdoutLogger) Log(level Level, msg string, context ...string) error

func (*StdoutLogger) Notice

func (logger *StdoutLogger) Notice(msg string, context ...string) error

func (*StdoutLogger) Warning

func (logger *StdoutLogger) Warning(msg string, context ...string) error

Jump to

Keyboard shortcuts

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