logger

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger provides an interface for logging. It wraps awesome existing go loggers with that interface. In that case, it is easy to change the log provider without breaking anything in your application. Additionally log level, fields, time duration or caller information can be added.

Index

Constants

This section is empty.

Variables

View Source
var ErrProvider = errors.New("logger: provider does not implement logger.Manager")

ErrProvider - Error message.

Functions

func Register

func Register(name string, provider Provider) error

Register a new logger provider by name.

Types

type Entry

type Entry struct {
	Level     Level
	Timestamp time.Time
	Message   string
	Fields    Fields
}

Entry struct holds all information for the log message.

type Fields

type Fields map[string]interface{}

Fields can be used to add more details to a log message.

func (Fields) Map

func (f Fields) Map() map[string]interface{}

Map converts the Fields to a map[string]interface{}. This can be handy for some providers.

type Level

type Level int32

Level type

const (
	TRACE Level = iota - 1
	DEBUG
	INFO
	WARNING
	ERROR
	PANIC
)

Level - the higher the more critical

func (Level) String

func (lvl Level) String() string

String converts the level code.

type Manager

type Manager interface {
	Trace(string)
	Debug(string)
	Info(msg string)
	Warning(msg string)
	Error(msg string)
	Panic(msg string)

	New() Manager
	WithFields(Fields) Manager
	WithTimer() Manager

	SetCallerFields(bool)
	SetLogLevel(Level)
}

Manager interface.

func Get

func Get(name string) (Manager, error)

Get a logger by the registered name. Default log level is DEBUG.

type Provider

type Provider interface {
	Log(Entry)
}

Provider interface.

Directories

Path Synopsis
Package logrus provider for the logger package.
Package logrus provider for the logger package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳