Skip to content

Commit a12674e

Browse files
committed
set the log level to LOG_LEVEL env variable
1 parent 4992ba5 commit a12674e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift

Lines changed: 6 additions & 1 deletion
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-
let logger: Logger
26+
var logger: Logger
2727
let eventLoop: EventLoop
2828

2929
public init(
@@ -55,6 +55,11 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
5555
throw LambdaRuntimeError(code: .runtimeCanOnlyBeStartedOnce)
5656
}
5757

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+
5863
try await LambdaRuntimeClient.withRuntimeClient(
5964
configuration: .init(ip: ip, port: port),
6065
eventLoop: self.eventLoop,

0 commit comments

Comments
 (0)