From 109aee806d8a8e638e490e686cc2d9f47daa1ba0 Mon Sep 17 00:00:00 2001 From: Pascal Zittlau Date: Tue, 4 Nov 2025 08:54:41 +0100 Subject: [PATCH] remove separate enabled function --- src/root.zig | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/root.zig b/src/root.zig index 2cb4dc0..4ccdff5 100644 --- a/src/root.zig +++ b/src/root.zig @@ -5,16 +5,14 @@ const builtin = @import("builtin"); pub const options: Options = if (@hasDecl(root, "faller_options")) root.faller_options else .{}; pub const Options = struct { + /// If more specialised ways to log are required replace this function. + /// This could be useful for logging to different things than `stderr` or for specifying whether + /// we should log with environment variables or `and`-based queries. function: fn ( comptime []const @Type(.enum_literal), comptime []const u8, anytype, ) void = defaultLogFunction, - /// If more specialised ways to determine whether something should be logged are required, - /// replace this function. - /// This could be useful for instance for specifying it with environment variables or - /// `and`-based queries. - enabled: fn (comptime []const @Type(.enum_literal)) bool = logEnabled, /// If there is at least one tag given this acts like a whitelist. Meaning if **any** of the /// tags is present it is logged. May be overwritten by `tags_disabled`. tags_enabled: []const @Type(.enum_literal) = &.{}, @@ -27,7 +25,7 @@ pub const Options = struct { pub const empty_logger = Logger{ .base_tags = &.{} }; -/// A Logger. Examples: +/// A tag based Logger. Examples: /// /// ```zig /// pub const module_log = Logger{ .base_tags = &.{.module} }; @@ -65,10 +63,7 @@ pub fn logTags( args: anytype, ) void { if (builtin.is_test and options.disabled_in_test) return; - const all_tags = comptime logger.base_tags ++ tags; - if (!options.enabled(all_tags)) return; - options.function(all_tags, format, args); } @@ -109,6 +104,7 @@ fn defaultLogFunction( args: anytype, ) void { if (tags.len == 0) @compileError("Need at least one tag for logging."); + if (comptime !logEnabled(tags)) return; comptime var prefix: []const u8 = ""; comptime for (tags) |tag| {