diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9beffa1..3999db3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v5 - uses: mlugg/setup-zig@v2 with: - version: 0.15.1 + version: master - run: zig build test --summary all - run: zig build run working-directory: example @@ -32,5 +32,5 @@ jobs: - uses: actions/checkout@v5 - uses: mlugg/setup-zig@v2 with: - version: 0.15.1 + version: master - run: zig fmt --check . diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c86f6bc..5de6687 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/configure-pages@v5 - uses: mlugg/setup-zig@v2 with: - version: 0.15.1 + version: master - run: zig build docs - uses: actions/upload-pages-artifact@v4 id: deployment diff --git a/build.zig.zon b/build.zig.zon index e4a0f68..be7771e 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,12 +1,12 @@ .{ .name = .axe, - .version = "0.7.0", + .version = "0.8.0", .fingerprint = 0x6c6a1e2ce5546233, - .minimum_zig_version = "0.15.1", + .minimum_zig_version = "0.16.0", .dependencies = .{ .zeit = .{ - .url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88", - .hash = "zeit-0.6.0-5I6bk0J9AgCVa0nnyL0lNY9Xa9F68hHq-ZarhuXNV-Jb", + .url = "git+https://github.com/elerch/zeit?ref=main#8190461dc1f892f6370fa9d5cd76690aac0e1c71", + .hash = "zeit-0.6.0-5I6bk99-AgDNMIDuw2Zcoe_9QYIpzwZJqeqMpU54egTd", }, }, .paths = .{ diff --git a/example/example.zig b/example/example.zig index f4b628d..831dc1b 100644 --- a/example/example.zig +++ b/example/example.zig @@ -18,8 +18,18 @@ pub fn main() !void { var gpa: std.heap.DebugAllocator(.{}) = .init; defer _ = gpa.deinit(); const allocator = gpa.allocator(); + + var threaded: std.Io.Threaded = .init(allocator); + defer threaded.deinit(); + const io = threaded.io(); + var env = try std.process.getEnvMap(allocator); defer env.deinit(); + + return juicyMain(allocator, io, env); +} + +pub fn juicyMain(allocator: std.mem.Allocator, io: std.Io, env: std.process.EnvMap) !void { var buffer: [256]u8 = undefined; { @@ -41,7 +51,7 @@ pub fn main() !void { .mutex = .none, // none by default }); var writer = std.fs.File.stdout().writer(&buffer); - try stdout_log.init(allocator, &.{&writer.interface}, &env); + try stdout_log.init(allocator, io, &.{&writer.interface}, &env); defer stdout_log.deinit(allocator); // wait we actually don't want stderr logging let's disable it @@ -57,7 +67,7 @@ pub fn main() !void { // writers, it should be called at the very start of the program. // std.log supports all the features of axe.Axe even additional writers, // time or custom mutex. - try std_log.init(std_log_fba.allocator(), null, &env); + try std_log.init(std_log_fba.allocator(), io, null, &env); // defer std_log.deinit(allocator); std.log.info("std.log.info with axe.Axe(.{{}})", .{}); @@ -90,7 +100,7 @@ pub fn main() !void { .mutex = .default, // default to std.Thread.Mutex }); var writer = f.writer(&buffer); - try log.init(allocator, &.{&writer.interface}, &env); + try log.init(allocator, io, &.{&writer.interface}, &env); defer log.deinit(allocator); log.debug("Hello! This will have no color if NO_COLOR is defined or if piped", .{}); @@ -115,7 +125,7 @@ pub fn main() !void { .color = .never, }); var writer = json_file.writer(&buffer); - try json_log.init(allocator, &.{&writer.interface}, &env); + try json_log.init(allocator, io, &.{&writer.interface}, &env); defer json_log.deinit(allocator); json_log.debug("\"json log\"", .{}); diff --git a/src/axe.zig b/src/axe.zig index 7404d94..882f4e7 100644 --- a/src/axe.zig +++ b/src/axe.zig @@ -70,6 +70,7 @@ pub fn Axe(comptime config: Config) type { var stderr_tty_config = defaultTtyConfig(config.color); var writers_tty_config = defaultTtyConfig(config.color); var timezone = if (config.time_format != .disabled) zeit.utc else {}; + var io: std.Io = undefined; var mutex = switch (config.mutex) { .none, .function => {}, .default => if (builtin.single_threaded) {} else std.Thread.Mutex{}, @@ -85,6 +86,7 @@ pub fn Axe(comptime config: Config) type { /// `env` is only used during initialization and is not stored. pub fn init( allocator: std.mem.Allocator, + _io: std.Io, additional_writers: ?[]const *std.Io.Writer, env: ?*const std.process.EnvMap, ) !void { @@ -96,9 +98,9 @@ pub fn Axe(comptime config: Config) type { var void_writer: std.Io.Writer.Discarding = .init(&.{}); try bogus.strftime(&void_writer.writer, config.time_format.strftime); } - + io = _io; if (config.time_format != .disabled) { - timezone = try zeit.local(allocator, env); + timezone = try zeit.local(allocator, io, env); } if (additional_writers) |_writers| { writers = try allocator.dupe(*std.Io.Writer, _writers); @@ -278,7 +280,7 @@ pub fn Axe(comptime config: Config) type { }; const time = if (config.time_format != .disabled) t: { - const now = zeit.instant(.{ .timezone = &timezone }) catch unreachable; + const now = zeit.instant(.{ .timezone = &timezone, .io = io }) catch unreachable; break :t now.time(); } else {}; @@ -746,7 +748,7 @@ test "log without styles" { .styles = .none, .quiet = true, }); - try log.init(std.testing.allocator, &.{&writer}, null); + try log.init(std.testing.allocator, std.testing.io, &.{&writer}, null); defer log.deinit(std.testing.allocator); log.info("Hello, {s}!", .{"world"}); @@ -787,7 +789,7 @@ test "log with complex config" { .quiet = true, .mutex = .default, }); - try log.init(std.testing.allocator, &.{&writer}, null); + try log.init(std.testing.allocator, std.testing.io, &.{&writer}, null); defer log.deinit(std.testing.allocator); log.info("Hello, {s}!", .{"world"}); @@ -824,7 +826,7 @@ test "time format" { }, }); log.quiet = true; - try log.init(std.testing.allocator, &.{&dest.writer}, null); + try log.init(std.testing.allocator, std.testing.io, &.{&dest.writer}, null); defer log.deinit(std.testing.allocator); log.info("Hello {c}", .{'W'}); @@ -856,7 +858,7 @@ test "json log" { .quiet = true, .color = .never, }); - try log.init(std.testing.allocator, &.{&writer}, null); + try log.init(std.testing.allocator, std.testing.io, &.{&writer}, null); defer log.deinit(std.testing.allocator); log.debug("\"json log\"", .{}); @@ -890,7 +892,7 @@ test "updateTtyConfig" { .color = .never, .quiet = true, }); - try log.init(std.testing.allocator, &.{&writer}, null); + try log.init(std.testing.allocator, std.testing.io, &.{&writer}, null); defer log.deinit(std.testing.allocator); log.debug("No color", .{});