DEV Community

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

Posted on

1

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>
Go

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more