logger

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: BSD-2-Clause Imports: 6 Imported by: 3

README

logger is a threadsafe logging library for go that does conditional logging controlled via UNIX-style loglevels.
Documentation is available through go doc.
The library is free software licensed under a 2-clause BSD license.

©2020 Jörg Walter

Documentation

Overview

The package logger provides a Logger type that can receive log records. Logger will only display a record if it is as severe as or more severe than the loglevel set for the Logger. Users of Logger therefore can control how much logging output they will see while running their program. A Logger can be used by multiple goroutines.

For usable loglevels see CONSTANTS.

Index

Constants

View Source
const (
	LevelPanic = iota
	LevelAlert
	LevelCritical
	LevelError
	LevelWarning
	LevelNotice
	LevelInfo
	LevelDebug
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LevelFlag

type LevelFlag int

func (*LevelFlag) Set

func (f *LevelFlag) Set(arg string) error

func (*LevelFlag) String

func (f *LevelFlag) String() string

type Logger

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

Logger is the data type used for sending log records to.

func New

func New(w io.Writer, level int, delimiter string) *Logger

New constructs a new Logger. It will print a log record to its given writer if it fulfills the Logger's designated loglevel or a more severe one. If you set the level to LevelCritical, the Logger will print all messages of LevelPanic or LevelAlert or LevelCritical.

func (*Logger) Alert

func (l *Logger) Alert(v ...interface{}) (n int, err error)

Alert sends a message of loglevel LevelAlert to the Logger.

func (*Logger) Critical

func (l *Logger) Critical(v ...interface{}) (n int, err error)

Critical sends a message of loglevel LevelCritical to the Logger.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{}) (n int, err error)

Debug sends a message of loglevel LevelDebug to the Logger.

func (*Logger) Die added in v0.2.1

func (l *Logger) Die(v ...interface{})

Die sends a message of loglevel LevelPanic to the Logger, then exits with code 1.

func (*Logger) Error

func (l *Logger) Error(v ...interface{}) (n int, err error)

Error sends a message of loglevel LevelError to the Logger.

func (*Logger) Info

func (l *Logger) Info(v ...interface{}) (n int, err error)

Info sends a message of loglevel LevelInfo to the Logger.

func (*Logger) Level

func (l *Logger) Level() int

Level returns the Logger's current loglevel as an integer.

func (*Logger) LevelStr

func (l *Logger) LevelStr() string

LevelStr returns the string representation of the Logger's current loglevel.

func (*Logger) Notice

func (l *Logger) Notice(v ...interface{}) (n int, err error)

Notice sends a message of loglevel LevelNotice to the Logger.

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{}) (n int, err error)

Panic sends a message of loglevel LevelPanic to the Logger. Please note that it does NOT call panic()!

func (*Logger) Println

func (l *Logger) Println(level int, v ...interface{}) (n int, err error)

Println writes the log message if its log level is equally severe or more severe than that set for the Logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

SetLevel sets a new loglevel for the Logger. Setting an invalid loglevel will cause a panic.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput changes the writer the Logger will write its messages to.

func (*Logger) SetTimeFormat

func (l *Logger) SetTimeFormat(format string)

SetTimeFormat takes a format string as defined in the "(t Time) Format" function of go's "time" module. If such a string is set, log records will display a timestamp formatted like specified by the format string. To remove timestamps from future log records, set the format string to "".

func (*Logger) TimeFormat

func (l *Logger) TimeFormat() string

TimeFormat returns the current format string for the timestamp. If it returns "", log records will have no timestamp.

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{}) (n int, err error)

Warning sends a message of loglevel LevelWarning to the Logger.

Jump to

Keyboard shortcuts

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