logger

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 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 ...any) (n int, err error)

Alert sends a message of loglevel LevelAlert to the Logger.

func (*Logger) Alertf added in v0.3.0

func (l *Logger) Alertf(format string, a ...any) (n int, err error)

Alertf sends a formatted message of loglevel LevelAlert to the Logger.

func (*Logger) Critical

func (l *Logger) Critical(v ...any) (n int, err error)

Critical sends a message of loglevel LevelCritical to the Logger.

func (*Logger) Criticalf added in v0.3.0

func (l *Logger) Criticalf(format string, a ...any) (n int, err error)

Criticalf sends a formatted message of loglevel LevelCritical to the Logger.

func (*Logger) Debug

func (l *Logger) Debug(v ...any) (n int, err error)

Debug sends a message of loglevel LevelDebug to the Logger.

func (*Logger) Debugf added in v0.3.0

func (l *Logger) Debugf(format string, a ...any) (n int, err error)

Debugf sends a formatted message of loglevel LevelDebug to the Logger.

func (*Logger) Die added in v0.2.1

func (l *Logger) Die(v ...any)

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

func (*Logger) Dief added in v0.3.0

func (l *Logger) Dief(format string, a ...any)

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

func (*Logger) Error

func (l *Logger) Error(v ...any) (n int, err error)

Error sends a message of loglevel LevelError to the Logger.

func (*Logger) Errorf added in v0.3.0

func (l *Logger) Errorf(format string, a ...any) (n int, err error)

Errorf sends a formatted message of loglevel LevelError to the Logger.

func (*Logger) Info

func (l *Logger) Info(v ...any) (n int, err error)

Info sends a message of loglevel LevelInfo to the Logger.

func (*Logger) Infof added in v0.3.0

func (l *Logger) Infof(format string, a ...any) (n int, err error)

Infof sends a formatted 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 ...any) (n int, err error)

Notice sends a message of loglevel LevelNotice to the Logger.

func (*Logger) Noticef added in v0.3.0

func (l *Logger) Noticef(format string, a ...any) (n int, err error)

Noticef sends a formatted message of loglevel LevelNotice to the Logger.

func (*Logger) Panic

func (l *Logger) Panic(v ...any) (n int, err error)

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

func (*Logger) Panicf added in v0.3.0

func (l *Logger) Panicf(format string, a ...any) (n int, err error)

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

func (*Logger) Printf added in v0.3.0

func (l *Logger) Printf(level int, format string, a ...any) (n int, err error)

Printf writes a formatted log message if the logger was configured to print the given level.

func (*Logger) Println

func (l *Logger) Println(level int, v ...any) (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 ...any) (n int, err error)

Warning sends a message of loglevel LevelWarning to the Logger.

func (*Logger) Warningf added in v0.3.0

func (l *Logger) Warningf(format string, a ...any) (n int, err error)

Warningf sends a formatted 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