DEV Community

Cover image for NPM debug style logging in Go
Derek Smith
Derek Smith

Posted on

NPM debug style logging in Go

I have always appreciated the debug logging pattern commonly used within NodeJS projects. As I worked more with go, I wanted to bring that logging pattern to the language.

kemba is a simple logging library that is a reimplementation of the npm debug module in hopes of bringing that capability to the language.

The kemba logger reads the DEBUG and KEMBA environment variables to determine if a log line should be output. The logger outputs to STDERR.

When it is not set, the logger will immediately return, taking no action.

When the value is set (ex. DEBUG=example:*,tool:details and/or KEMBA=plugin:fxn:start), the logger will determine if it should be enabled when instantiated.

The value of these flags can be a simple regex alternative where a wildcard (*) are replaced with .* and all terms are prepended with ^ and appended with $. If a term does not include a wildcard, then an exact match it required.

Mentioned in Awesome<br>

Top comments (0)