clogger

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 11 Imported by: 10

Documentation

Overview

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

Index

Constants

View Source
const (
	FormatPlain = Format("plain")
	FormatJSON  = Format("json")
)

Formats supported by Logger

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 Config added in v0.2.0

type Config struct {
	Out    string `toml:"out"`
	Err    string `toml:"err"`
	Format Format `toml:"format"`
}

Config holds the params needed to configure Logger

func LoadConfig added in v0.2.0

func LoadConfig(appConfig cconfig.Loader) (Config, error)

LoadConfig loads Config from app's config

type Format added in v0.2.0

type Format string

Format represents the output format of log statements

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(config Config) (Logger, error)

NewWithConfig creates a Logger based on the provided config.

func NewWithWriters

func NewWithWriters(out, err io.Writer, format Format) 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.

func NewZapLogger added in v0.4.0

func NewZapLogger(config Config, lc *clifecycle.Lifecycle) (Logger, error)

NewZapLogger creates a Logger that internally uses go.uber.org/zap for logging

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