Skip to content

Commit

Permalink
Merge pull request #36 from outfoxx/fix/logging
Browse files Browse the repository at this point in the history
Fix logging unsupported on previous os versions
  • Loading branch information
kdubb authored Dec 8, 2022
2 parents 292a6d3 + 9a7f2bf commit 78fa0f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 10 additions & 6 deletions Sources/Sunday/EventSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -483,7 +483,7 @@ public class EventSource {
return
}

logger.debug("Received Rrror \(error)")
logger.debug("Received Error: \(error.localizedDescription, privacy: .public)")

fireErrorEvent(error: error)

Expand Down Expand Up @@ -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)")
}

}
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sunday/NetworkRequestFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions Sources/SundayServer/HTTPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)")

}
}
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 78fa0f2

Please sign in to comment.