Skip to content

Commit

Permalink
more log fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jul 13, 2024
1 parent cf9e1e4 commit 79c64f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub fn main() !void {
_ = thread.create("gui", gui.go, dummy_payload, guiback) catch unreachable;
_ = thread.create("heartbeat", heartbeat.go, dummy_payload, heartback) catch unreachable;
while (true) {
util.log("while", .{});
statewalk(alloc);
util.log("thread.wait()/epoll", .{});
thread.wait(); // main ipc listener
Expand Down
2 changes: 1 addition & 1 deletion src/statemachine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ pub fn needNetRefresh() bool {

pub fn setState(new_state: States) void {
state = new_state;
warn("STATE: {s}\n", .{@tagName(state)});
warn("STATE: {s}", .{@tagName(state)});
}
9 changes: 8 additions & 1 deletion src/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ pub fn log(comptime msg: []const u8, args: anytype) void {
//const tz = std.os.timezone.tz_minuteswest;
var tz = std.posix.timezone{ .tz_minuteswest = 0, .tz_dsttime = 0 };
std.posix.gettimeofday(null, &tz); // does not set tz
const time_str = "Z"; //std.fmt.allocPrint(alloc, "{d}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2}:{d:0>2}", .{ yday.year, mday.month.numeric(), mday.day_index + 1, dsec.getHoursIntoDay(), dsec.getMinutesIntoHour(), dsec.getSecondsIntoMinute() }) catch unreachable;
const now_ms = std.time.milliTimestamp() + tz.tz_minuteswest * std.time.ms_per_hour;
const esec = std.time.epoch.EpochSeconds{ .secs = @as(u64, @intCast(@divTrunc(now_ms, std.time.ms_per_s))) };
const eday = esec.getEpochDay();
const yday = eday.calculateYearDay();
const mday = yday.calculateMonthDay();
const dsec = esec.getDaySeconds();

const time_str = std.fmt.allocPrint(alloc, "{d}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2}:{d:0>2}", .{ yday.year, mday.month.numeric(), mday.day_index + 1, dsec.getHoursIntoDay(), dsec.getMinutesIntoHour(), dsec.getSecondsIntoMinute() }) catch unreachable;
std.debug.print("{s}[tid#{d}/{s:9}] " ++ msg ++ "\n", .{ time_str, tid, tid_name } ++ args);
}

Expand Down

0 comments on commit 79c64f3

Please sign in to comment.