Documentation ¶
Overview ¶
"Logging extensions" - https://joonas.fi/2018/12/04/an-idea-to-fix-gos-logging-mess/
Index ¶
- Variables
- func CustomLevelPrefix(levelName string) string
- func Filter(filter *regexp.Regexp, matches *log.Logger) *log.Logger
- func NonNil(ref *log.Logger) *log.Logger
- func OutputToAnotherLog(another *log.Logger) io.Writer
- func Prefix(prefix string, parent *log.Logger) *log.Logger
- func RedirectGlobalStdLog(to *log.Logger)
- func StandardLogger() *log.Logger
- func StandardLoggerTo(sink io.Writer) *log.Logger
- type Leveled
Constants ¶
This section is empty.
Variables ¶
var Discard = log.New(io.Discard, "", 0)
a logger that discards its output
Functions ¶
func CustomLevelPrefix ¶
sometimes you may need to pipe log output from logging interfaces with more levels than what we have declared here. prefer uppercase: Prefix(CustomLevelPrefix("WARN"))
func Filter ¶
pipes Logger's output (io.Writer) into another Logger, but only if entry matches regex
func NonNil ¶
helper for libraries in getting an alwas non-nil logger. if a logger given to you was nil, you get a Discard logger back, which you can call safely - it doesn't write anywhere
func OutputToAnotherLog ¶
pipes Logger's output (io.Writer) into another Logger
func RedirectGlobalStdLog ¶
func StandardLogger ¶
centralized place for creating "standard" stderr logger in a way that supports suppressing log timestamps if a mechanism around it (Docker/systemd) would add one anyway
Types ¶
type Leveled ¶
type Leveled struct { Debug *log.Logger // usually hidden, maybe noisy, but can be enabled for debugging deep problems Info *log.Logger // something interesting happened Warn *log.Logger // something unexpected happened, but not yet jeopardizing the application Error *log.Logger // something exceptional operations usually should look at: like I/O (network/disk) failed, service call failed, security problem etc. // convenience for if some component needs raw (= non-leveled) Logger Original *log.Logger }
purposefully minimal # of log levels. I kind of agree with this post ..:
https://dave.cheney.net/2015/11/05/lets-talk-about-logging
.. with the exception, that Error levels are justified