From 9a7f2bf47de2c0e1b1fe769ea06d1fb949c4c933 Mon Sep 17 00:00:00 2001 From: Kevin Wooten Date: Wed, 7 Dec 2022 16:49:39 -0700 Subject: [PATCH] Fix logging unsupported on previous os versions --- Sources/Sunday/EventSource.swift | 16 ++++++++++------ Sources/Sunday/NetworkRequestFactory.swift | 2 +- Sources/SundayServer/HTTPConnection.swift | 8 +++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Sources/Sunday/EventSource.swift b/Sources/Sunday/EventSource.swift index 7011ee0d..213845e5 100644 --- a/Sources/Sunday/EventSource.swift +++ b/Sources/Sunday/EventSource.swift @@ -472,7 +472,7 @@ public class EventSource { return } - logger.debug("Received Data count=\(data.count)") + logger.debug("Received Data: count=\(data.count)") eventParser.process(data: data, dispatcher: dispatchParsedEvent) } @@ -483,7 +483,7 @@ public class EventSource { return } - logger.debug("Received Rrror \(error)") + logger.debug("Received Error: \(error.localizedDescription, privacy: .public)") fireErrorEvent(error: error) @@ -591,13 +591,13 @@ public class EventSource { if let retry = info.retry { if let retryTime = Int(retry.trimmingCharacters(in: .whitespaces), radix: 10) { - logger.debug("update retry timeout: retryTime=\(retryTime)") + logger.debug("update retry timeout: retryTime=\(retryTime)ms") self.retryTime = .milliseconds(retryTime) } else { - logger.debug("ignoring invalid retry timeout message: retry=\(retry)") + logger.debug("ignoring invalid retry timeout message: retry=\(retry, privacy: .public)") } } @@ -622,7 +622,9 @@ public class EventSource { if let onMessageCallback = onMessageCallback { - logger.debug("dispatch onMessage: event=\(info.event ?? ""), id=\(info.id ?? "")") + logger.debug( + "dispatch onMessage: event=\(info.event ?? "", privacy: .public), id=\(info.id ?? "", privacy: .public)" + ) queue.async { onMessageCallback(info.event, info.id, info.data) @@ -636,7 +638,9 @@ public class EventSource { for eventHandler in eventHandlers { - logger.debug("dispatch listener: event=\(info.event ?? ""), id=\(info.id ?? "")") + logger.debug( + "dispatch listener: event=\(info.event ?? "", privacy: .public), id=\(info.id ?? "", privacy: .public)" + ) eventHandler.value(event, info.id, info.data) } diff --git a/Sources/Sunday/NetworkRequestFactory.swift b/Sources/Sunday/NetworkRequestFactory.swift index bbc17285..7b987c24 100644 --- a/Sources/Sunday/NetworkRequestFactory.swift +++ b/Sources/Sunday/NetworkRequestFactory.swift @@ -504,7 +504,7 @@ public class NetworkRequestFactory: RequestFactory { continuation.yield(event) } catch { - eventStreamLogger.error("Unable to decode event: \(error)") + eventStreamLogger.error("Unable to decode event: \(error.localizedDescription, privacy: .public)") return } diff --git a/Sources/SundayServer/HTTPConnection.swift b/Sources/SundayServer/HTTPConnection.swift index 38011f14..7d708613 100644 --- a/Sources/SundayServer/HTTPConnection.swift +++ b/Sources/SundayServer/HTTPConnection.swift @@ -159,7 +159,7 @@ public class HTTPConnection { public func handleReceive(content: Data?, isComplete: Bool, error: Error?) { guard let server = server, error == nil, !isComplete else { if let error = error { - logger.error("network connection error: \(error)") + logger.error("network connection error: \(error.localizedDescription, privacy: .public)") } return close() } @@ -201,7 +201,7 @@ public class HTTPConnection { try dispatcher(request, response) } catch { - logger.error("http processing error: \(error)") + logger.error("http processing error: \(error.localizedDescription, privacy: .public)") } } @@ -249,7 +249,9 @@ public final class NetworkHTTPConnection: HTTPConnection { override public func send(data: Data, context: String, completion: ((Error?) -> Void)? = nil) { transport.send(content: data, completion: .contentProcessed { error in if let error = error { - self.logger.error("send error while '\(context)': \(error)") + self.logger.error( + "send error while '\(context, privacy: .public)': \(error.localizedDescription, privacy: .public)" + ) } completion?(error) })