What it is
blackboxlog is a small Go library that gives my projects a consistent way to write logs.
It uses Go’s built-in log/slog package and returns an ordinary logger, with a few defaults and conventions that make the output easier to read and search in Blackbox.
Why I made it
Building Blackbox solved the problem of collecting logs in one place, but it also made me think about what my applications were actually writing.
If one project prints a plain sentence, another writes JSON, and a third doesn’t include enough information to tell what failed, having all those messages in one place only helps so much.
I didn’t want to keep setting up logging a little differently in every new Go project, either.
So I made a small shared package for it. The idea is to keep the format consistent without inventing a whole new logging system or adding another service that every application needs to contact.
How it works
A project calls blackboxlog.New and gets back a normal *slog.Logger. By default, it writes structured JSON to stderr, where Docker can capture it. In development, it can switch to more readable text output.
The package also gives me a consistent way to set log levels, attach a request ID to messages, and include useful fields like the operation being performed or how long it took.
It hides values under field names that look sensitive, such as passwords and tokens, and provides a Secret type for values that should always be redacted. That isn’t a substitute for being careful about what gets logged, but it’s a useful extra safeguard.
There’s no Blackbox connection, API token, or background process involved. The application writes its logs as usual, Docker captures them, and Blackbox collects them separately. Applications that don’t use blackboxlog are still collected.
Where it’s at
The first version is released, and Blackbox itself already uses it for its own logging.
I want to keep this one intentionally small. It’s a shared convention for my Go projects, not a framework that needs to grow every time I add something new.
As more of my projects adopt it, I’ll adjust the common fields and defaults where there’s a real reason to, while keeping the package simple to use.
Changelog
0.0.0latest6 new
added
New: a*slog.Loggerwriting one JSON record per line to stderr, or readable text whenAPP_ENV=dev, with UTC times.LOG_FORMATandLOG_LEVELsettings, withOptionsto override them. A value it can’t use falls back to the default and logs an error.- Values under sensitive field names, such as
passwordandtoken, are written as[redacted]. Secret: a string that stays hidden in logs,fmtand JSON under any field name.WithRequestIDandRequestID: addsrequest_idto records logged with a context.- The logging standard in the README: the fields every project uses, and when to use each level.
More to look at
all projects-
I push code to GitHub, and my server takes it from there.
-
My own little vault for the passwords, keys, and secrets my projects need.
-
One consistent way for my Go projects to communicate with Cove.