From b9f1827b634082ae37e97b4f402ff5dbaed0d2d3 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 8 Dec 2023 20:26:17 +0100 Subject: [PATCH] Test logger --- Sources/App/DeviceManager.swift | 13 ++++++++++++- Sources/App/configure.swift | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/App/DeviceManager.swift b/Sources/App/DeviceManager.swift index 3497cfb..0e60693 100644 --- a/Sources/App/DeviceManager.swift +++ b/Sources/App/DeviceManager.swift @@ -33,6 +33,12 @@ final class DeviceManager { private var requestInProgress: CheckedContinuation? private var receivedMessageData: Data? + var logger: Logger? + + private func printAndFlush(_ message: String) { + logger?.notice(.init(stringLiteral: message)) + } + init(deviceKey: Data, remoteKey: Data, deviceTimeout: Int64, serverStatus: Metric) { self.deviceKey = deviceKey self.remoteKey = remoteKey @@ -89,6 +95,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") self.receivedMessageData = nil return receivedMessageData } @@ -97,12 +104,16 @@ final class DeviceManager { self.requestInProgress = continuation } await updateMessageCountMetric() + printAndFlush("[INFO] Message completed") return result } private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) { eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in - self?.resumeDeviceRequest(with: .deviceTimedOut) + guard let self else { + printAndFlush("[INFO] Message completed") + } + self.resumeDeviceRequest(with: .deviceTimedOut) } } diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 7e2022c..4bab95b 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -37,7 +37,7 @@ public func configure(_ app: Application) async throws { let (deviceKey, remoteKey) = try loadKeys(at: keyFile) deviceManager = DeviceManager(deviceKey: deviceKey, remoteKey: remoteKey, deviceTimeout: config.deviceTimeout, serverStatus: status) - + deviceManager.logger = app.logger routes(app) provider = .init(observer: monitor, accessManager: config.authenticationTokens)