go_goutils/logging/doc.go

50 lines
2.1 KiB
Go
Raw Normal View History

2022-01-05 05:15:38 -05:00
/*
Package logging implements and presents various loggers under a unified interface, making them completely swappable.
These particular loggers (logging.Logger) available are:
2022-09-06 01:01:39 -04:00
NullLogger
StdLogger
FileLogger
SystemDLogger (Linux only)
SyslogLogger (Linux only)
WinLogger (Windows only)
2022-01-05 05:15:38 -05:00
2022-09-06 01:01:39 -04:00
There is a seventh type of logging.Logger, MultiLogger, that allows for multiple loggers to be written to with a single call.
As you may have guessed, NullLogger doesn't actually log anything but is fully "functional" as a logging.Logger.
2022-01-05 05:15:38 -05:00
Note that for some Loggers, the prefix may be modified - "literal" loggers (StdLogger and FileLogger) will append a space to the end of the prefix.
If this is undesired (unlikely), you will need to modify (Logger).Prefix and run (Logger).Logger.SetPrefix(yourPrefixHere) for the respective logger.
2022-01-05 05:15:38 -05:00
Every logging.Logger type has the following methods that correspond to certain "levels".
Alert(s string, v ...interface{}) (err error)
Crit(s string, v ...interface{}) (err error)
Debug(s string, v ...interface{}) (err error)
Emerg(s string, v ...interface{}) (err error)
Err(s string, v ...interface{}) (err error)
Info(s string, v ...interface{}) (err error)
Notice(s string, v ...interface{}) (err error)
Warning(s string, v ...interface{}) (err error)
Not all loggers implement the concept of levels, so approximations are made when/where possible.
In each of the above methods, s is the message that is optionally in a fmt.Sprintf-compatible format.
If it is, the values to fmt.Sprintf can be passed as v.
Note that in the case of a MultiLogger, err (if not nil) will be a (r00t2.io/goutils/)multierr.MultiError.
logging.Logger types also have the following methods:
2022-01-16 06:55:29 -05:00
DoDebug(d bool) (err error)
2022-09-07 06:03:28 -04:00
GetDebug() (d bool)
2022-01-16 06:55:29 -05:00
SetPrefix(p string) (err error)
GetPrefix() (p string, err error)
Setup() (err error)
Shutdown() (err error)
2022-01-05 05:15:38 -05:00
In some cases, Logger.Setup and Logger.Shutdown are no-ops. In other cases, they perform necessary initialization/cleanup and closing of the logger.
It is recommended to *always* run Setup and Shutdown before and after using, respectively, regardless of the actual logging.Logger type.
*/
package logging