Skip to content

Commit

Permalink
Set the log level to LOG_LEVEL env variable (#417)
Browse files Browse the repository at this point in the history
* set the log level to LOG_LEVEL env variable

* remove need for `var logger`

* swift-format

* [ci] update static sdk to 6.0.2
  • Loading branch information
sebsto authored Nov 7, 2024
1 parent 4992ba5 commit 7016dfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ jobs:
# https://github.com/swiftlang/github-workflows/issues/34
musl:
runs-on: ubuntu-latest
container: swift:6.0-noble
container: swift:6.0.2-noble
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install SDK
run: swift sdk install https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481
run: swift sdk install https://download.swift.org/swift-6.0.2-release/static-sdk/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum aa5515476a403797223fc2aad4ca0c3bf83995d5427fb297cab1d93c68cee075
- name: Build
run: swift build --swift-sdk x86_64-swift-linux-musl
6 changes: 6 additions & 0 deletions Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
) {
self.handlerMutex = NIOLockedValueBox(handler)
self.eventLoop = eventLoop

// by setting the log level here, we understand it can not be changed dynamically at runtime
// developers have to wait for AWS Lambda to dispose and recreate a runtime environment to pickup a change
// this approach is less flexible but more performant than reading the value of the environment variable at each invocation
var log = logger
log.logLevel = Lambda.env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info
self.logger = logger
}

Expand Down

0 comments on commit 7016dfc

Please sign in to comment.