ConciseLog.zig — A User-Friendly Logging Library Born for Zig, an Excellent Alternative to std.log

ConciseLog.zig


project: GitHub - ntu0831/ConciseLog.zig · GitHub

I was previously preparing to develop a CLI program, and after searching around for logging libraries, I found none satisfactory. Either they were structured logging libraries, or the unstructured logging libraries seemed rather incomplete, and their compatibility with std.Io didn’t seem great.

So I decided to develop a relatively traditional but feature-rich unstructured logging library (I also considered developing a structured logging library, but the standard library doesn’t provide a structured logging API, so I gave up on that idea).

Additionally, I quite like the logging interface design in the standard library, so when developing this library I strove to adapt to the standard library’s logging interface (in the initial design I considered making the logger an interface type, but that wouldn’t be compatible with std.log.scoped, so I stopped there).

Some design sharing:

- Initially I considered using a manager pattern (similar to std.Build) to manage resources (File, Buffer) onto another object, which would keep the Logger Context’s internal logic and the structure itself lean, but this increased initialization complexity, so I abandoned it.
- This library reuses std.Io.Writer to implement long log output, achieving it in the self-implemented drain by acquiring from the buffer pool queue.

Additionally, this library has issues yet to be improved: observability design, which I’ll refine later.

By the way, the project’s benchmark is being written, and I’m also developing ComptimeConciseLog.zig to bring more mechanism-level optimizations to the logging library, striving to eliminate if-else branches on the hot path at compile time, as well as inline-expand patterns, etc. The benchmark will be released together at that time. ComptimeConciseLog.zig is coming soon.

Some feature highlights:

- Zero dependencies & zero extra allocations: does not depend on any components outside the standard library, and introduces no memory allocations on the logging path.
- Simple interface: init, deinit, setLevel, Log, disable
- An excellent replacement for std.log: perfectly fits std.options.logFn\std.log.scoped
- Powerful customization: supports writer, pattern, formatter
- Built-in time support
- Supports long logs
- Supports blocking and non-blocking modes

Everyone is welcome to use it, and I will maintain this project long-term.

If you have any questions, feel free to provide feedback, and I will reply promptly and communicate to resolve them.

Supported Zig versions

  • 0.17.0
1 Like

concise* :slight_smile:

Hi, interesting.
But it’s not clear to me what are the upside compared to std.log

1 Like

Thanks for your reply.

std.log is just an interface, and the default std.options.logFn is very primitive: it doesn’t support asynchronous writes, timestamp output, custom writers, etc. If you want to write your own std.options.logFn to implement these features, it will not only make your program architecture more complex but also divert effort from your project.

So here is a convenient framework for you to choose from. You can simply import it into your Zig project to replace std.log, and it supports asynchronous writes, custom writers, timestamp output, and other rich features.

Thanks for your reply. I’ve already fixed the issue.