add(timestamp): timestamp build configuration option to add timestamps before log messages
All checks were successful
Run Tests / test (push) Successful in 9m33s
Run Tests / lint (push) Successful in 9m43s

This commit is contained in:
2024-08-28 22:25:06 +02:00
parent 510b3ddfcf
commit eb7e78697c
3 changed files with 32 additions and 20 deletions

View File

@@ -4,6 +4,14 @@ const std = @import("std");
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// build options to customize the log message formating
const include_timestamp = b.option(bool, "timestamp", "Enable inclusion of timestamps in log messages (default: true)") orelse true;
const options = b.addOptions();
options.addOption(bool, "timestamp", include_timestamp);
const options_module = options.createModule();
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
@@ -21,7 +29,9 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/zlog.zig"),
.target = target,
.optimize = optimize,
.link_libc = include_timestamp, // uses c std library <time.h>
});
zlog_module.addImport("build_options", options_module);
const exe = b.addExecutable(.{
.name = "zlog",