Skip to content

Commit 7114adb

Browse files
committed
remove need for var logger
1 parent a12674e commit 7114adb

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import NIOCore
2323
public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: StreamingLambdaHandler {
2424
// TODO: We want to change this to Mutex as soon as this doesn't crash the Swift compiler on Linux anymore
2525
let handlerMutex: NIOLockedValueBox<Handler?>
26-
var logger: Logger
26+
let logger: Logger
2727
let eventLoop: EventLoop
2828

2929
public init(
@@ -33,6 +33,12 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
3333
) {
3434
self.handlerMutex = NIOLockedValueBox(handler)
3535
self.eventLoop = eventLoop
36+
37+
// by setting the log level here, we understand it can not be changed dynamically at runtime
38+
// developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change
39+
// this approach is less flexible but more performant than reading the value of the environment variable at each invocation
40+
var log = logger
41+
log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info
3642
self.logger = logger
3743
}
3844

@@ -55,11 +61,6 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
5561
throw LambdaRuntimeError(code: .runtimeCanOnlyBeStartedOnce)
5662
}
5763

58-
// by setting the log level here, we understand it can not be changed dynamically at runtime
59-
// developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change
60-
// this approach is less flexible but more performant than reading the value of the environment variable at each invocation
61-
self.logger.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info
62-
6364
try await LambdaRuntimeClient.withRuntimeClient(
6465
configuration: .init(ip: ip, port: port),
6566
eventLoop: self.eventLoop,

0 commit comments

Comments
 (0)