minilog

package
v0.0.0-...-f825296 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

minilog extends Go's logging functionality to allow for multiple loggers, each one with their own logging level. To use minilog, call AddLogger() to set up each desired logger, then use the package-level logging functions defined to send messages to all defined loggers.

Index

Constants

View Source
const (
	Reset      = "\x1b[0m"
	Bright     = "\x1b[1m"
	Dim        = "\x1b[2m"
	Underscore = "\x1b[4m"
	Blink      = "\x1b[5m"
	Reverse    = "\x1b[7m"
	Hidden     = "\x1b[8m"

	FgBlack   = "\x1b[30m"
	FgRed     = "\x1b[31m"
	FgGreen   = "\x1b[32m"
	FgYellow  = "\x1b[33m"
	FgBlue    = "\x1b[34m"
	FgMagenta = "\x1b[35m"
	FgCyan    = "\x1b[36m"
	FgWhite   = "\x1b[37m"

	BgBlack   = "\x1b[40m"
	BgRed     = "\x1b[41m"
	BgGreen   = "\x1b[42m"
	BgYellow  = "\x1b[43m"
	BgBlue    = "\x1b[44m"
	BgMagenta = "\x1b[45m"
	BgCyan    = "\x1b[46m"
	BgWhite   = "\x1b[47m"
)

Some color constants for output

View Source
const DefaultLevel = ERROR

Variables

View Source
var (
	LevelFlag   = DefaultLevel
	VerboseFlag bool
	FileFlag    string
)

Functions

func AddFilter

func AddFilter(name string, filter string) error

func AddLogRing

func AddLogRing(name string, l *Ring, level Level)

func AddLogger

func AddLogger(name string, output io.Writer, level Level, color bool)

Adds a logger set to log only events at level specified or higher. output: io.Writer instance to which to log (can be os.Stderr or os.Stdout) level: one of the minilogging levels defined as a constant

func AddSyslog

func AddSyslog(network, raddr, tag string, level Level) error

Helper function to add syslog output by connecting to address raddr on the specified network. Events are logged with a specified tag. Calling more than once overwrites existing syslog writers. If network == "local", log to the local syslog daemon.

func Debug

func Debug(format string, arg ...interface{})

func Debugln

func Debugln(arg ...interface{})

func DelFilter

func DelFilter(name string, filter string) error

func DelLogger

func DelLogger(name string)

Remove a named logger that was added using AddLogger

func Error

func Error(format string, arg ...interface{})

func Errorln

func Errorln(arg ...interface{})

func Fatal

func Fatal(format string, arg ...interface{})

func Fatalln

func Fatalln(arg ...interface{})

func Filters

func Filters(name string) ([]string, error)

func Info

func Info(format string, arg ...interface{})

func Infoln

func Infoln(arg ...interface{})

func Init

func Init()

Setup log according to flags and OS. Replaces the logSetup() that each package used to have.

func LogAll

func LogAll(i io.Reader, level Level, name string)

Log all input from an io.Reader, splitting on lines, until EOF. LogAll starts a goroutine and returns immediately.

func Loggers

func Loggers() []string

func SetLevel

func SetLevel(name string, level Level) error

Change a log level for a named logger.

func SetLevelAll

func SetLevelAll(level Level)

SetLevelAll changes the log level for all loggers to the provided level

func Warn

func Warn(format string, arg ...interface{})

func Warnln

func Warnln(arg ...interface{})

func WillLog

func WillLog(level Level) bool

WillLog returns true if logging to a specific log level will result in actual logging. Useful if the logging text itself is expensive to produce.

Types

type Level

type Level int
const (
	DEBUG Level
	INFO
	WARN
	ERROR
	FATAL
)

Log levels supported: DEBUG -> INFO -> WARN -> ERROR -> FATAL

func GetLevel

func GetLevel(name string) (Level, error)

Return the log level for a named logger.

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel returns the log level from a string.

func (*Level) Set

func (l *Level) Set(s string) (err error)

func (Level) String

func (l Level) String() string

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

func NewRing

func NewRing(size int) *Ring

func (*Ring) Dump

func (l *Ring) Dump() []string

Dump returns the log messages from oldest to newest.

func (*Ring) Println

func (l *Ring) Println(v ...interface{})

Println mimic golang's log.Logger.Output and prepends the time

Jump to

Keyboard shortcuts

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