Introducing Logly: A High-Performance Logging Library for Zig

Muhammad Fiaz
2 min read

A technical overview of Logly v0.1.0, a thread-safe, modular logging library for the Zig ecosystem focusing on performance and developer ergonomics.

Share:

Logging is foundational to systems programming. In the Zig ecosystem, which is still maturing, there exists a need for robust, standardized tooling. Logly is a new logging library designed to fill this gap, prioritizing performance, modularity, and thread safety.

Design Philosophy

Logly was built with three core principles:

  1. Zero Allocation on Hot Path: Logging should not trigger the memory allocator during standard operations unless strictly necessary (e.g., formatting dynamic strings).
  2. Modularity: The core logger is decoupled from the output destination (Sink).
  3. Ergonomics: The API should be intuitive for developers coming from other modern languages.

Key Features

Modular Sinks

Logly supports multiple output targets simultaneously.

  • ConsoleSink: Thread-safe standard output logging.
  • FileSink: Rotating file logs with configurable size and time policies.
  • NetworkSink (Planned): Asynchronous logging to remote aggregators.

Thread Safety

All sinks are thread-safe by default, utilizing efficient synchronization primitives (mutexes/atomics) to ensure data integrity in concurrent applications without blocking the main execution thread significantly.

Rich Formatting

Support for structured logging (JSON) and customizable text formats allows integration with observability platforms like Datadog, Grafana Loki, or simple terminal viewing.

Performance

Logly is designed to be fast and efficient, with minimal overhead and zero allocation on the hot path.

You can find the benchmarks in the release notes.

Getting Started

Logly is available via the Zig package manager.

// build.zig.zon
.{
    .dependencies = .{
        .logly = .{
            .url = "https://github.com/muhammad-fiaz/logly/archive/v0.1.0.tar.gz",
            .hash = "logly-0.1.0-kZjLe3E9CgAODAxnYR91gJFNlruu5Kr7EQtfE85XMJIh"
        },
    },
}

Usage in your application:

const logly = @import("logly");

pub fn main() !void {
    var logger = try logly.init(.{ .level = .info });
    defer logger.deinit();

    try logger.info("Server started on port {d}", .{8080});
}

Roadmap

The project is currently in v0.1.0. Future development will focus on asynchronous logging capabilities, compression for file sinks, and deeper integration with the Zig standard library’s std.log interface.

Contributions are welcome on GitHub.


Related Posts