This is a super simple project which aims to help out with setting up logging correctly in your project. It is a true drop in replacement for
logrus logger atm.
The entire logging framework is configured via a single environment variable
LOG. The variable is a comma delimited list
of packages and their respective log-levels. (falling back to InfoLevel if not configured).
This logger should be fully able to work colored on windows! TTY detection may fail though, so to ensure that it does not set the environment variable CLICOLOR_FORCE=1 in your shell.
Some bonus modifiers exist for the log config:
- ln enables printing of line numbers
- gr adds number of goroutines to each log statement
- grl adds number of goroutines to each log statement and starts a loop printing the number of routines every second
- log.Must, log.MustFatal if the passed error is not nil log it and throw a panic or end the program
- log.Should, log.ShouldWarn if the passed error is not nul just log it, returns true if error has been printed
- log.Wrap can be used with Should and must functions to provide additional error information (eg: log.Should(log.Wrap(err, "on testing %s", somedata)))
- log.Indent can be used to prety print the public fields of a structure (eg: log.Info(log.Indent(myStructure)))
LOG=foo=debug,bar=warn go run
This configures the
foo package at loglevel Debug, the bar package at loglevel Warn and the default/fallback logger at Info.
LOG=foo=info,debug,bar=warn go run
This is the same as the previous example, except foo is now at loglevel Info, and the default loglevel is Debug.
LOG=debug go run
This example sets everything to Debug.