Skip to content

Commit 86c56f1

Browse files
committed
Make sure "sending event" log msg and event dump are in the same line
This way, we avoid other `os_log` calls getting in between `os_log` and `dump` and breaking the association between the two which makes the logs harder to understand.
1 parent 6cc170e commit 86c56f1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Sources/Track.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class Track {
2222
parselyTracker.startFlushTimer();
2323

2424
pixel.beacon(event: event)
25-
os_log("Sending an event from Track", log: OSLog.tracker, type:.debug)
26-
dump(event.toDict())
25+
os_log_sending_event(event)
2726
}
2827

2928
func pageview(url: String, urlref: String = "", metadata: ParselyMetadata?, extra_data: Dictionary<String, Any>?, idsite: String) {
@@ -82,3 +81,18 @@ class Track {
8281
videoManager.sendHeartbeats()
8382
}
8483
}
84+
85+
/// Utitlity to log sending event with a dump of the event.
86+
private func os_log_sending_event(_ event: Event, log: OSLog = .tracker, type: OSLogType = .debug) {
87+
var eventDump = DumpOutput()
88+
dump(event.toDict(), to: &eventDump)
89+
os_log("Sending an event from Track:\n%@", log: log, type: type, eventDump.content)
90+
}
91+
92+
private struct DumpOutput: TextOutputStream {
93+
private(set) var content = ""
94+
95+
mutating func write(_ string: String) {
96+
content.append(string)
97+
}
98+
}

0 commit comments

Comments
 (0)