loggr

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

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 8 Imported by: 0

README

go-loggr

A logging and error handling library.

Documentation

Overview

loggr is a simple logging and error handling library.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Level defines the current log level
	Level = LogLevelAll

	// Outputs contains LoggerOut instances. Those filter messages by the log level and writes them to the defined
	// writer. As default only Stdout is added as output with the loglevel "ALL".
	Outputs = []LoggerOut{{os.Stdout, LogLevelAll}}

	// EntryOutputs defines a list of handlers for handling Entrys instead of the already formatted string.
	// As en example those handlers can be used to store the log entry in a database or as an json object.
	EntryOutputs []LoggerEntryOut

	// TimeFormat defines how the time should be formatted.
	// The time formatting of Go is used.
	// It will be available in the Format string as {{.Time}}
	TimeFormat = "2006-05-04 01:02:03"

	// Format is a string used to format an entry into an string, which will be written to the Outputs.
	Format = "[{{.Time}}] [{{.Level}}] {{.Message}}"
)
View Source
var (
	// LogLevelNames defines how the log level should be named in the output.
	// You can change this map depending on your needs.
	// If a log level is not mentioned within this map, the log level will be translated to UNKNOWN.
	// The log level name will be available for the format string as {{.Level}}
	LogLevelNames = map[LogLevel]string{
		LogLevelNone:    "NONE",
		LogLevelError:   "ERROR",
		LogLevelWarning: "WARNING",
		LogLevelInfo:    "INFO",
		LogLevelDebug:   "DEBUG",
	}
)

Functions

func Debug

func Debug(msg ...interface{})

func DebugF

func DebugF(format string, a ...interface{})

func Error

func Error(msg ...interface{})

func ErrorF

func ErrorF(format string, a ...interface{})

func FatalErr

func FatalErr(err error)

func Info

func Info(msg ...interface{})

func InfoF

func InfoF(format string, a ...interface{})

func Log

func Log(level LogLevel, msg ...interface{})

func LogEntry

func LogEntry(level LogLevel, entry Entry)

func LogErr

func LogErr(err error)

func LogWarn

func LogWarn(err error)

func PanicErr

func PanicErr(err error)

func Warning

func Warning(msg ...interface{})

func WarningF

func WarningF(format string, a ...interface{})

Types

type Entry

type Entry struct {
	Time     time.Time `json:"time",bson:"time",yaml:"time"`
	LogLevel LogLevel  `json:"level",bson:"level",yaml:"level"`
	Message  string    `json:"msg",bson:"msg",yaml:"msg"`
}

Entry contains the metadata for the log entry.

func (Entry) String

func (e Entry) String() string

String formats the entry depending on TimeFormat, Format and LogLevelNames. The result contains already a new line at the end.

type EntryFunc

type EntryFunc func(entry Entry)

EntryFunc is a function definition for handling log entries.

type LogLevel

type LogLevel int

LogLevel describes how many information should be logged.

const (
	LogLevelNone LogLevel = iota
	LogLevelError
	LogLevelWarning
	LogLevelInfo
	LogLevelDebug

	LogLevelAll = LogLevelDebug
)

func (LogLevel) String

func (l LogLevel) String() string

type LoggerEntryOut

type LoggerEntryOut struct {
	HandlerFunc EntryFunc
	LogLevel    LogLevel
}

type LoggerOut

type LoggerOut struct {
	Writer   io.Writer
	LogLevel LogLevel
}

func (LoggerOut) Write

func (l LoggerOut) Write(msg string, level LogLevel)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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