remove separate enabled function
This commit is contained in:
14
src/root.zig
14
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| {
|
||||
|
||||
Reference in New Issue
Block a user