clogger

package
v0.0.0-...-5538d7f Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package clogger provides a Logger interface that can be used to log messages and errors

Index

Constants

View Source
const (
	LevelDebug = Level(iota + 1)
	LevelInfo
	LevelWarn
	LevelError
)

Pre-defined log levels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int

Level represents the severity level of a log.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	WithTags(tags map[string]interface{}) Logger

	Debug(msg string)
	Info(msg string)
	Warn(msg string, err error)
	Error(msg string, err error)
}

Logger can be used to log messages and errors.

func New

func New() Logger

New returns a Logger implementation that can logs to console.

func NewNoop

func NewNoop() Logger

NewNoop returns a no-op implementation of Logger. Useful in passing it as a valid logger in unit tests.

func NewRecorder

func NewRecorder(logs *[]RecordedLog) Logger

NewRecorder returns an implementation of Logger that keeps a record of each log. Useful in unit tests when logs need to be tested.

func NewWithConfig

func NewWithConfig(appConfig cconfig.Config) (Logger, error)

NewWithConfig creates a Logger based on the provided config. Example TOML config: clogger out = "./logs.out" err = "./logs.err".

func NewWithWriters

func NewWithWriters(out, err io.Writer) Logger

NewWithWriters creates a Logger that uses the provided writers. out is used for debug and info levels. err is used for warn and error levels.

type RecordedLog

type RecordedLog struct {
	Level Level
	Tags  map[string]interface{}
	Msg   string
	Error error
}

RecordedLog represents a single log.

Jump to

Keyboard shortcuts

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