Skip to content

Would like a single place to configure where zigdown writes logs and debug output #23

@deevus

Description

@deevus

Related to #22, but separate enough to split out.

zigdown currently writes diagnostic output through two different channels:

  1. std.log.scoped(.utils) in src/lib/utils.zig and .ts_queries in src/lib/ts_queries.zig. I can intercept these from the root source file via std_options.logFn, but that's process-wide.
  2. debug.print in src/lib/debug.zig, which writes to a global stream set via debug.setStream().

To fully silence zigdown (for a CLI where stderr is meaningful output) I have to wire both. Here's what I'm doing today:

// main.zig — intercept std.log scopes
pub const std_options: std.Options = .{
    .logFn = md.log.zigdownSupressingLog,
};
// md/log.zig — drop known zigdown scopes
pub fn zigdownSupressingLog(
    comptime level: std.log.Level,
    comptime scope: @TypeOf(.enum_literal),
    comptime format: []const u8,
    args: anytype,
) void {
    switch (scope) {
        .present, .server, .tree_sitter, .syntax, .utils => return,
        else => std.log.defaultLog(level, scope, format, args),
    }
}
// md/render.zig — redirect debug.print into /dev/null
var discarding_writer: std.Io.Writer.Discarding = .init(&.{});
zigdown.debug.setStream(&discarding_writer.writer);

It works. But two globals don't compose well when zigdown is embedded in a longer-running process or a test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions