Skip to content
Open
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
16 changes: 16 additions & 0 deletions Sources/VSDDaemon/Logging.swift
Original file line number Diff line number Diff line change
@@ -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)
}