log

package
v0.0.0-...-8876515 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package log provides utilities for logging

Index

Constants

View Source
const DateFormat = "2006-01-02 15:04:05.000"

DateFormat describes how the date in a log message is formatted

View Source
const Format = "[{lvl}] [{name}] {date}: {message}"

Format describes how a log message is formatted

Variables

View Source
var CutoffLevels = make(map[string]Level)

CutoffLevels maps the loggers by name to their cutoff level

View Source
var DateProvider = func() string { return time.Now().Format(DateFormat) }

DateProvider returns the formatted date as string, use by the logger

View Source
var DefaultCutoffLevel = LevelInfo

DefaultCutoffLevel is used as cutoff level for loggers with a name for whom no cutoff level is defined in CutoffLevels

View Source
var ErrorWriter io.Writer = os.Stderr

ErrorWriter is the writer to which Warn/Error/Fatal log messages are written

View Source
var LevelNames = map[Level]LevelName{
	LevelTrace: {"TRACE", "TRC"},
	LevelDebug: {"DEBUG", "DBG"},
	LevelInfo:  {"INFO", "INF"},
	LevelWarn:  {"WARN", "WRN"},
	LevelError: {"ERROR", "ERR"},
	LevelFatal: {"FATAL", "FTL"},
}

LevelNames contains the full and short names of the log levels

View Source
var OutputWriter io.Writer = os.Stdout

OutputWriter is the writer to which normal log messages are written (level < LevelWarn)

Functions

This section is empty.

Types

type Level

type Level int

Level is a log level

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelOff
)

noinspection GoUnusedConst The different log levels

func LevelByName

func LevelByName(name string) Level

LevelByName retrieves the level with the given name (defaults to LevelOff)

func (Level) FullName

func (l Level) FullName() string

FullName returns the full name of a log level

func (Level) ShortName

func (l Level) ShortName() string

ShortName returns the short name of a log level

type LevelName

type LevelName struct {
	Full  string
	Short string
}

LevelName holds the full and short name of a log level

type Logger

type Logger func(msg string, level Level)

Logger is a function to log a single message

func GetLogger

func GetLogger(name string) Logger

GetLogger returns a Logger to log from a given package

func (Logger) Debug

func (l Logger) Debug(msg string)

Debug logs a message with LevelDebug

func (Logger) Debugf

func (l Logger) Debugf(format string, a ...interface{})

Debugf formats a message and logs it with LevelDebug

func (Logger) Error

func (l Logger) Error(msg string)

Error logs a message with LevelError

func (Logger) Errorf

func (l Logger) Errorf(format string, a ...interface{})

Errorf formats a message and logs it with LevelError

func (Logger) Fatal

func (l Logger) Fatal(msg string)

Fatal logs a message with LevelFatal

func (Logger) Fatalf

func (l Logger) Fatalf(format string, a ...interface{})

Fatalf formats a message and logs it with LevelFatal

func (Logger) Info

func (l Logger) Info(msg string)

Info logs a message with LevelInfo

func (Logger) Infof

func (l Logger) Infof(format string, a ...interface{})

Infof formats a message and logs it with LevelInfo

func (Logger) Trace

func (l Logger) Trace(msg string)

Trace logs a message with LevelTrace

func (Logger) Tracef

func (l Logger) Tracef(format string, a ...interface{})

Tracef formats a message and logs it with LevelTrace

func (Logger) Warn

func (l Logger) Warn(msg string)

Warn logs a message with LevelWarn

func (Logger) Warnf

func (l Logger) Warnf(format string, a ...interface{})

Warnf formats a message and logs it with LevelWarn

Jump to

Keyboard shortcuts

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