Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -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 = .{
Expand Down
18 changes: 14 additions & 4 deletions example/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

{
Expand All @@ -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
Expand All @@ -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(.{{}})", .{});
Expand Down Expand Up @@ -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", .{});
Expand All @@ -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\"", .{});
Expand Down
18 changes: 10 additions & 8 deletions src/axe.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {};

Expand Down Expand Up @@ -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"});
Expand Down Expand Up @@ -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"});
Expand Down Expand Up @@ -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'});
Expand Down Expand Up @@ -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\"", .{});
Expand Down Expand Up @@ -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", .{});
Expand Down
Loading