I wrote this some time ago when I realized that the default log package forced the software to exit when you called the Error functions. It also does not include any context; the package, file, or line number which are immensely helpful when troubleshooting.
While there are other packages that provide the functionality I would want, some mirror the default package’s behavior, and most are relatively large or have additional dependencies.
So I decided to write my own, which was so simple I was amazed how big some of the other packages are.
Instead of the myriad of conflicting behaviors that a developer could embed into their application for configuration (eg.
--quiet, literally every full or partial log level name, or a log level with severity as a value, I’ve seen it all). Developers can ignore all that now, just let the user set
LOG_LEVEL environment variable.
It provides standardized severities which defaults to “Error”. I generally only use around 3~4 of them, but all of them are included.
It can determine color support in the terminal and will log in color (disabled if output is redirected).
It offers context, so you can easily debug code by tracking down the file and line number the error occurred.
All output goes to stderr, which is the optimal sane default to avoid messing with expected application output.
It is concurrently safe, using a package level mutex.
It comes with comprehensive tests, and benchmarks.
I highly recommend trying it out.
written on 2017-04-13