Skip to content

Ratakor/axe

Repository files navigation

Axe 🪓

A fully customizable logging library for the Zig programming language.

Features

  • Drop-in replacement for std.Options.LogFn
  • Minimal (less than 1000 LOC)
  • Extremely fast performance with intensive use of comptime
  • Parallel file logging with support for stderr & custom writers
  • Full custom format support with sane defaults & JSON support
  • Source location support with axe.logAt(@src(), ...)
  • Built-in time support with zeit
  • Built-in colors support
    • Automatic tty detection
    • Windows support
    • NO_COLOR & CLICOLOR_FORCE environment variables support
  • Built-in thread safety with multiple mutex interface available

Installation

Add it to an existing project with this command:

zig fetch --save git+https://github.com/Ratakor/axe

Then add the module to build.zig.

const axe = b.dependency("axe", .{}).module("axe");
exe.root_module.addImport("axe", axe);

Usage

const std = @import("std");
const axe = @import("axe").Axe(.{
    // Config goes here.
    .mutex = .{ .function = .progress_stderr },
});

// Replace the default logFn.
pub const std_options: std.Options = .{
    .logFn = axe.log,
};

pub fn main() !void {
    const allocator = std.heap.page_allocator;
    try axe.init(allocator, null, null);
    defer axe.deinit(allocator);

    std.log.debug("Hello {s}!", .{ "World" });
    axe.infoAt(@src(), "Some info with source location", .{});
}

Check example.zig for more!

Docs

See the API Documentation.

About

A logging library for zig

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •