logex

package
v0.0.0-...-a5f7211 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 26

README

See my blog post about fixing Go´s logging mess.

Documentation

Overview

"Logging extensions" - https://joonas.fi/2018/12/04/an-idea-to-fix-gos-logging-mess/

Index

Constants

This section is empty.

Variables

View Source
var Discard = log.New(io.Discard, "", 0)

a logger that discards its output

Functions

func CustomLevelPrefix

func CustomLevelPrefix(levelName string) string

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

func Filter(filter *regexp.Regexp, matches *log.Logger) *log.Logger

pipes Logger's output (io.Writer) into another Logger, but only if entry matches regex

func NonNil

func NonNil(ref *log.Logger) *log.Logger

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

func OutputToAnotherLog(another *log.Logger) io.Writer

pipes Logger's output (io.Writer) into another Logger

func Prefix

func Prefix(prefix string, parent *log.Logger) *log.Logger

Prefix() creates a new Logger whose output is piped to parent logger with a prefix

func RedirectGlobalStdLog

func RedirectGlobalStdLog(to *log.Logger)

func StandardLogger

func StandardLogger() *log.Logger

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

func StandardLoggerTo

func StandardLoggerTo(sink io.Writer) *log.Logger

same as StandardLogger() but with explicit sink

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

func Levels

func Levels(parent *log.Logger) *Leveled

Jump to

Keyboard shortcuts

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