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 const.
Index ¶
- func Loglevels() map[Level]string
- func SetupDefaultLogger(w io.Writer, level Level, delimiter string)
- type Level
- type LevelFlag
- type Logger
- func (l *Logger) Alert(v ...any) (n int, err error)
- func (l *Logger) Alertf(format string, a ...any) (n int, err error)
- func (l *Logger) Critical(v ...any) (n int, err error)
- func (l *Logger) Criticalf(format string, a ...any) (n int, err error)
- func (l *Logger) Debug(v ...any) (n int, err error)
- func (l *Logger) Debugf(format string, a ...any) (n int, err error)
- func (l *Logger) Die(v ...any)
- func (l *Logger) Dief(format string, a ...any)
- func (l *Logger) Error(v ...any) (n int, err error)
- func (l *Logger) Errorf(format string, a ...any) (n int, err error)
- func (l *Logger) Info(v ...any) (n int, err error)
- func (l *Logger) Infof(format string, a ...any) (n int, err error)
- func (l *Logger) Level() Level
- func (l *Logger) Notice(v ...any) (n int, err error)
- func (l *Logger) Noticef(format string, a ...any) (n int, err error)
- func (l *Logger) Panic(v ...any) (n int, err error)
- func (l *Logger) Panicf(format string, a ...any) (n int, err error)
- func (l *Logger) Printf(level Level, format string, a ...any) (n int, err error)
- func (l *Logger) Println(level Level, v ...any) (n int, err error)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) SetTimeFormat(format string)
- func (l *Logger) TimeFormat() string
- func (l *Logger) Warning(v ...any) (n int, err error)
- func (l *Logger) Warningf(format string, a ...any) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Level ¶ added in v0.4.0
type Level int
Represents a loglevel.
const ( LevelInvalid Level = iota //Not a loglevel, represents an invalid loglevel internally. LevelPanic //Reports a crash or a program termination that was necessary to prevent something more severe. LevelAlert //Reports a condition that needs immediate action by the user. LevelCritical //Reports a hard error. LevelError //Reports a normal error condition. LevelWarning //Reports something that isn't an error but might cause problems later. LevelNotice //Reports conditions that are no errors but may require special handling. LevelInfo //Reports normal user information about expected conditions. LevelDebug //Reports information that is only interesting for debugging or development. )
func ParseLevel ¶ added in v0.4.0
Tries to associate the input string with a specific loglevel. Returns that loglevel on success, on failure LevelInvalid and an error is returned.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the data type used for sending log records to.
func Default ¶ added in v0.4.1
func Default() *Logger
Returns the default logger, will panic if SetupDefaultLogger() has not been called yet.
func New ¶
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) Alertf ¶ added in v0.3.0
Alertf sends a formatted message of loglevel LevelAlert to the Logger.
func (*Logger) Criticalf ¶ added in v0.3.0
Criticalf sends a formatted message of loglevel LevelCritical to the Logger.
func (*Logger) Debugf ¶ added in v0.3.0
Debugf sends a formatted message of loglevel LevelDebug to the Logger.
func (*Logger) Die ¶ added in v0.2.1
Die sends a message of loglevel LevelPanic to the Logger, then exits with code 1.
func (*Logger) Dief ¶ added in v0.3.0
Dief sends a formatted message of loglevel LevelPanic to the Logger, then exits with code 1.
func (*Logger) Errorf ¶ added in v0.3.0
Errorf sends a formatted message of loglevel LevelError to the Logger.
func (*Logger) Infof ¶ added in v0.3.0
Infof sends a formatted message of loglevel LevelInfo to the Logger.
func (*Logger) Noticef ¶ added in v0.3.0
Noticef sends a formatted message of loglevel LevelNotice to the Logger.
func (*Logger) Panic ¶
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
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
Printf writes a formatted log message if the logger was configured to print the given level.
func (*Logger) Println ¶
Println writes the log message if its log level is equally severe or more severe than that set for the Logger.
func (*Logger) SetLevel ¶
SetLevel sets a new loglevel for the Logger. Setting an invalid loglevel will cause a panic.
func (*Logger) SetTimeFormat ¶
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 ¶
TimeFormat returns the current format string for the timestamp. If it returns "", log records will have no timestamp.