Compare commits
3 Commits
2dea92dcd9
...
4099617646
| Author | SHA1 | Date | |
|---|---|---|---|
| 4099617646 | |||
| f489c96de2 | |||
| 6efcfcded9 |
@@ -1,6 +1,6 @@
|
|||||||
.{
|
.{
|
||||||
.name = .faller,
|
.name = .faller,
|
||||||
.version = "0.1.0",
|
.version = "0.2.0",
|
||||||
.minimum_zig_version = "0.15.1",
|
.minimum_zig_version = "0.15.1",
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|||||||
16
src/root.zig
16
src/root.zig
@@ -1,11 +1,9 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const root = @import("root");
|
const root = @import("root");
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
pub const options: Options = if (@hasDecl(root, "faller_options")) root.faller_options else .{};
|
pub const options: Options = if (@hasDecl(root, "faller_options")) root.faller_options else .{};
|
||||||
|
|
||||||
/// The base logger to create scopes from. Or just use `Logger` directly.
|
|
||||||
pub const logger = Logger(&.{});
|
|
||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
function: fn (
|
function: fn (
|
||||||
comptime []const @Type(.enum_literal),
|
comptime []const @Type(.enum_literal),
|
||||||
@@ -24,8 +22,18 @@ pub const Options = struct {
|
|||||||
/// tags is present it **isn't** logged. May overwrite `tags_enabled`.
|
/// tags is present it **isn't** logged. May overwrite `tags_enabled`.
|
||||||
tags_disabled: []const @Type(.enum_literal) = &.{},
|
tags_disabled: []const @Type(.enum_literal) = &.{},
|
||||||
buffer_size: u64 = 64,
|
buffer_size: u64 = 64,
|
||||||
|
disabled_in_test: bool = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Used to create a logger from.
|
||||||
|
///
|
||||||
|
/// Examples:
|
||||||
|
/// ```zig
|
||||||
|
/// const logger = Logger(&.{.my_module});
|
||||||
|
/// const foo_bar_logger = Logger(&.{.foo, .bar});
|
||||||
|
/// const foo_bar_log = foo_bar_logger.log;
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
pub fn Logger(comptime base_tags: []const @Type(.enum_literal)) type {
|
pub fn Logger(comptime base_tags: []const @Type(.enum_literal)) type {
|
||||||
return struct {
|
return struct {
|
||||||
/// Creates a new logger with an extended tag prefix.
|
/// Creates a new logger with an extended tag prefix.
|
||||||
@@ -48,6 +56,8 @@ pub fn Logger(comptime base_tags: []const @Type(.enum_literal)) type {
|
|||||||
comptime format: []const u8,
|
comptime format: []const u8,
|
||||||
args: anytype,
|
args: anytype,
|
||||||
) void {
|
) void {
|
||||||
|
if (options.disabled_in_test) return;
|
||||||
|
|
||||||
const all_tags = comptime base_tags ++ tags;
|
const all_tags = comptime base_tags ++ tags;
|
||||||
if (!options.enabled(all_tags)) return;
|
if (!options.enabled(all_tags)) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user