From 43a68005812e9ec1d4fdb36c53eb58e713a1b46d Mon Sep 17 00:00:00 2001 From: Nicklas Andersson Date: Wed, 19 Aug 2026 12:37:54 +0200 Subject: [PATCH] Timestamp log output The log recorded only the order of events, not when they happened. That is not enough to diagnose an intermittent fault: a device that dropped twice in a minute and one that dropped twice in a day produce identical logs, and the difference is most of the diagnosis. Declare print at module scope so it shadows Swift.print. Every existing call site gains a timestamp without being modified, and new code gets it by default. Co-Authored-By: Claude Opus 5 --- Sources/VSDDaemon/Logging.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Sources/VSDDaemon/Logging.swift diff --git a/Sources/VSDDaemon/Logging.swift b/Sources/VSDDaemon/Logging.swift new file mode 100644 index 0000000..3ff8082 --- /dev/null +++ b/Sources/VSDDaemon/Logging.swift @@ -0,0 +1,16 @@ +import Foundation + +private let logTimestamp: DateFormatter = { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + return formatter +}() + +/// Shadows Swift.print for the whole module, so every existing call site gains +/// a timestamp without being touched. Without one, the log records only the +/// order of events, which is not enough to tell a device that dropped twice in +/// a minute from one that dropped twice in a day. +func print(_ items: Any..., separator: String = " ", terminator: String = "\n") { + let body = items.map { "\($0)" }.joined(separator: separator) + Swift.print("[\(logTimestamp.string(from: Date()))] \(body)", terminator: terminator) +}