adding debug logs levels, implementing some physical device functions
This commit is contained in:
@@ -2,6 +2,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const zdt = @import("zdt");
|
||||
const root = @import("root");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
comptime {
|
||||
if (!@hasDecl(root, "DRIVER_NAME")) {
|
||||
@@ -12,11 +13,6 @@ comptime {
|
||||
}
|
||||
}
|
||||
|
||||
const is_posix = switch (builtin.os.tag) {
|
||||
.windows, .uefi, .wasi => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
var indent_level: usize = 0;
|
||||
|
||||
pub fn indent() void {
|
||||
@@ -34,7 +30,7 @@ pub fn unindent() void {
|
||||
}
|
||||
|
||||
pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal), comptime format: []const u8, args: anytype) void {
|
||||
if (!std.process.hasEnvVarConstant(root.DRIVER_LOGS_ENV_NAME)) {
|
||||
if (lib.getLogVerboseLevel() == .None) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,13 +61,16 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
|
||||
var writer: *std.Io.Writer = &stderr_writer.interface;
|
||||
var out_config = std.Io.tty.Config.detect(stderr_file);
|
||||
|
||||
const timezone = zdt.Timezone.tzLocal(std.heap.page_allocator) catch zdt.Timezone.UTC;
|
||||
var timezone = zdt.Timezone.tzLocal(std.heap.page_allocator) catch zdt.Timezone.UTC;
|
||||
defer timezone.deinit();
|
||||
const now = zdt.Datetime.now(.{ .tz = &timezone }) catch return;
|
||||
|
||||
out_config.setColor(writer, .magenta) catch {};
|
||||
writer.print("[" ++ root.DRIVER_NAME ++ " StrollDriver ", .{}) catch return;
|
||||
writer.print("[StrollDriver ", .{}) catch return;
|
||||
out_config.setColor(writer, .cyan) catch {};
|
||||
writer.print(root.DRIVER_NAME, .{}) catch return;
|
||||
out_config.setColor(writer, .yellow) catch {};
|
||||
writer.print("{d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch return;
|
||||
writer.print(" {d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch return;
|
||||
out_config.setColor(writer, .magenta) catch {};
|
||||
writer.print("]", .{}) catch return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user