Test logger
This commit is contained in:
parent
4489092a6f
commit
b9f1827b63
@ -33,6 +33,12 @@ final class DeviceManager {
|
|||||||
private var requestInProgress: CheckedContinuation<Data, Error>?
|
private var requestInProgress: CheckedContinuation<Data, Error>?
|
||||||
private var receivedMessageData: Data?
|
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<ServerStatus>) {
|
init(deviceKey: Data, remoteKey: Data, deviceTimeout: Int64, serverStatus: Metric<ServerStatus>) {
|
||||||
self.deviceKey = deviceKey
|
self.deviceKey = deviceKey
|
||||||
self.remoteKey = remoteKey
|
self.remoteKey = remoteKey
|
||||||
@ -89,6 +95,7 @@ final class DeviceManager {
|
|||||||
|
|
||||||
// Check if a full message has already been received
|
// Check if a full message has already been received
|
||||||
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
|
if let receivedMessageData, receivedMessageData.count == SignedMessage.size {
|
||||||
|
printAndFlush("[INFO] Full message from socket collected early")
|
||||||
self.receivedMessageData = nil
|
self.receivedMessageData = nil
|
||||||
return receivedMessageData
|
return receivedMessageData
|
||||||
}
|
}
|
||||||
@ -97,12 +104,16 @@ final class DeviceManager {
|
|||||||
self.requestInProgress = continuation
|
self.requestInProgress = continuation
|
||||||
}
|
}
|
||||||
await updateMessageCountMetric()
|
await updateMessageCountMetric()
|
||||||
|
printAndFlush("[INFO] Message completed")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
|
private func startTimeoutForDeviceRequest(on eventLoop: EventLoop) {
|
||||||
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
|
eventLoop.scheduleTask(in: .seconds(deviceTimeout)) { [weak self] in
|
||||||
self?.resumeDeviceRequest(with: .deviceTimedOut)
|
guard let self else {
|
||||||
|
printAndFlush("[INFO] Message completed")
|
||||||
|
}
|
||||||
|
self.resumeDeviceRequest(with: .deviceTimedOut)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public func configure(_ app: Application) async throws {
|
|||||||
|
|
||||||
let (deviceKey, remoteKey) = try loadKeys(at: keyFile)
|
let (deviceKey, remoteKey) = try loadKeys(at: keyFile)
|
||||||
deviceManager = DeviceManager(deviceKey: deviceKey, remoteKey: remoteKey, deviceTimeout: config.deviceTimeout, serverStatus: status)
|
deviceManager = DeviceManager(deviceKey: deviceKey, remoteKey: remoteKey, deviceTimeout: config.deviceTimeout, serverStatus: status)
|
||||||
|
deviceManager.logger = app.logger
|
||||||
routes(app)
|
routes(app)
|
||||||
|
|
||||||
provider = .init(observer: monitor, accessManager: config.authenticationTokens)
|
provider = .init(observer: monitor, accessManager: config.authenticationTokens)
|
||||||
|
Loading…
Reference in New Issue
Block a user