Skip to content
/ zlog Public

Simple structured logging for Zig

License

Notifications You must be signed in to change notification settings

jcalabro/zlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zlog

Simple structured logging for Zig.

Usage

Add the following dependency to your build.zig.zon file's dependencies section with:

zig fetch --save https://github.com/jcalabro/zlog/archive/main.tar.gz

Add the following to your build.zig:

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

Once at startup in your program, call init:

const std = @import("std");
const zlog = @import("zlog");

pub fn main() !void {
    try zlog.init(.{
        .allocator = std.heap.c_allocator,
        .level = .dbg,
        .regions = "all",
        .fp = std.io.getStdOut(),
    });
    defer zlog.deinit();

    // your code here...
}

Then, you can use the logger throughout your program like so:

const log = logger.Logger.init("myregion");

fn foo() void {
    // formatted and unformatted log functions for each level are available
    log.debugf("hello {s}", .{"world"});
    log.info("hello world");
    log.warn("hello world");
    log.err("hello world");
    log.fatal("hello world"); // exits the program
}

About

Simple structured logging for Zig

Topics

Resources

License

Stars

Watchers

Forks

Languages