log

package
v0.0.0-...-5ddfa25 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(logger Logger) (err error)

Set configures the singleton Logger. This method must only be called once, and before calling Get the first time.

Types

type Logger

type Logger interface {
	Err(m string)
	Warning(m string)
	Info(m string)
	Debug(m string)
	AuditPanic()
	AuditInfo(string)
	AuditObject(string, interface{})
	AuditErr(string)
}

A Logger logs messages with explicit priority levels. It is implemented by a logging back-end as provided by New() or NewMock().

Example
Output:

�[31m�[1mE000000 log.test [AUDIT] Error Audit�[0m
�[33mW000000 log.test Warning Audit�[0m

func Get

func Get() Logger

Get obtains the singleton Logger. If Set has not been called first, this method initializes with basic defaults. The basic defaults cannot error, and subsequent access to an already-set Logger also cannot error, so this method is error-safe.

func New

func New(log *syslog.Writer, stdoutLogLevel int, syslogLogLevel int) (Logger, error)

New returns a new Logger that uses the given syslog.Writer as a backend.

type Mock

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

Mock is a logger that stores all log messages in memory to be examined by a test.

func NewMock

func NewMock() *Mock

NewMock creates a mock logger.

func UseMock

func UseMock() *Mock

UseMock sets a mock logger as the default logger, and returns it.

func (*Mock) AuditErr

func (log *Mock) AuditErr(msg string)

AuditErr can format an error for auditing; it does so at ERR level.

func (*Mock) AuditInfo

func (log *Mock) AuditInfo(msg string)

AuditInfo sends an INFO-severity message that is prefixed with the audit tag, for special handling at the upstream system logger.

func (*Mock) AuditObject

func (log *Mock) AuditObject(msg string, obj interface{})

AuditObject sends an INFO-severity JSON-serialized object message that is prefixed with the audit tag, for special handling at the upstream system logger.

func (*Mock) AuditPanic

func (log *Mock) AuditPanic()

AuditPanic catches panicking executables. This method should be added in a defer statement as early as possible

func (*Mock) Clear

func (m *Mock) Clear()

Clear resets the log buffer.

func (*Mock) Debug

func (log *Mock) Debug(msg string)

Debug level messages pass through normally.

func (*Mock) Err

func (log *Mock) Err(msg string)

Err level messages are always marked with the audit tag, for special handling at the upstream system logger.

func (*Mock) GetAll

func (m *Mock) GetAll() []string

GetAll returns all messages logged since instantiation or the last call to Clear().

The caller must not modify the returned slice or its elements.

func (*Mock) GetAllMatching

func (m *Mock) GetAllMatching(reString string) []string

GetAllMatching returns all messages logged since instantiation or the last Clear() whose text matches the given regexp. The regexp is accepted as a string and compiled on the fly, because convenience is more important than performance.

The caller must not modify the elements of the returned slice.

func (*Mock) Info

func (log *Mock) Info(msg string)

Info level messages pass through normally.

func (*Mock) Warning

func (log *Mock) Warning(msg string)

Warning level messages pass through normally.

Jump to

Keyboard shortcuts

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