Log all messages instead of printing

This commit is contained in:
Christoph Hagen 2023-12-10 19:34:30 +01:00
parent 1a1eeb6547
commit ad1c959ead

View File

@ -92,7 +92,7 @@ final class DeviceManager {
// Check if a full message has already been received
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
printAndFlush("[INFO] Full message from socket collected early")
log("[INFO] Full message from socket collected early")
self.receivedMessageData = nil
return receivedMessageData
}
@ -101,14 +101,14 @@ final class DeviceManager {
self.requestInProgress = continuation
}
await updateMessageCountMetric()
printAndFlush("[INFO] Message completed")
log("[INFO] Message completed")
return result
}
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
guard let self else {
print("[INFO] Message completed")
log("[INFO] No reference to self after timeout of message")
return
}
self.resumeDeviceRequest(with: .deviceTimedOut)
@ -117,7 +117,7 @@ final class DeviceManager {
private func resumeDeviceRequest(with data: Data) {
guard let receivedMessageData else {
printAndFlush("[WARN] Received \(data.count) bytes after message completion")
log("[WARN] Received \(data.count) bytes after message completion")
self.requestInProgress = nil
return
}
@ -129,12 +129,12 @@ final class DeviceManager {
}
self.receivedMessageData = nil
guard let requestInProgress else {
printAndFlush("[WARN] Received \(newData.count) bytes, but no continuation to resume")
log("[WARN] Received \(newData.count) bytes, but no continuation to resume")
return
}
self.requestInProgress = nil
guard newData.count == SignedMessage.size else {
printAndFlush("[WARN] Received \(newData.count) bytes, expected \(SignedMessage.size) for a message.")
log("[WARN] Received \(newData.count) bytes, expected \(SignedMessage.size) for a message.")
requestInProgress.resume(throwing: MessageResult.invalidMessageSizeFromDevice)
return
}
@ -143,13 +143,13 @@ final class DeviceManager {
private func resumeDeviceRequest(with result: MessageResult) {
guard let receivedMessageData else {
printAndFlush("[WARN] Result after message completed: \(result)")
log("[WARN] Result after message completed: \(result)")
self.requestInProgress = nil
return
}
self.receivedMessageData = nil
guard let requestInProgress else {
printAndFlush("[WARN] Request in progress (\(receivedMessageData.count) bytes), but no continuation found for result: \(result)")
log("[WARN] Request in progress (\(receivedMessageData.count) bytes), but no continuation found for result: \(result)")
return
}
self.requestInProgress = nil
@ -163,13 +163,13 @@ final class DeviceManager {
func processDeviceResponse(_ buffer: ByteBuffer) {
guard let data = buffer.getData(at: 0, length: buffer.readableBytes) else {
print("Failed to get data buffer received from device")
log("Failed to get data buffer received from device")
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
return
}
guard data.count == SignedMessage.size else {
print("Invalid size of device message: \(data.count)")
log("Invalid size of device message: \(data.count)")
self.resumeDeviceRequest(with: .invalidMessageSizeFromDevice)
return
}
@ -205,7 +205,7 @@ final class DeviceManager {
try? await socket.close()
guard let self else {
print("[WARN] No reference to self to handle text over socket")
log("[WARN] No reference to self to handle text over socket")
return
}
self.didCloseDeviceSocket()
@ -213,7 +213,7 @@ final class DeviceManager {
socket.onBinary { [weak self] _, data in
guard let self else {
print("[WARN] No reference to self to process binary data on socket")
log("[WARN] No reference to self to process binary data on socket")
return
}
self.processDeviceResponse(data)
@ -221,7 +221,7 @@ final class DeviceManager {
socket.onClose.whenComplete { [weak self] _ in
guard let self else {
print("[WARN] No reference to self to handle socket closing")
log("[WARN] No reference to self to handle socket closing")
return
}
self.didCloseDeviceSocket()