Skip to content

Commit 7a7e90f

Browse files
committed
Give user the possibility to pass their logger to the lambda runtime
1 parent b2811a5 commit 7a7e90f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import class Foundation.JSONDecoder
2323
import class Foundation.JSONEncoder
2424
#endif
2525

26+
import Logging
27+
2628
public struct LambdaJSONEventDecoder: LambdaEventDecoder {
2729
@usableFromInline let jsonDecoder: JSONDecoder
2830

@@ -85,10 +87,12 @@ extension LambdaCodableAdapter {
8587
extension LambdaRuntime {
8688
/// Initialize an instance with a `LambdaHandler` defined in the form of a closure **with a non-`Void` return type**.
8789
/// - Parameters:
90+
/// - logger: The logger to use for the runtime. Defaults to a logger with label "LambdaRuntime".
8891
/// - decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
8992
/// - encoder: The encoder object that will be used to encode the generic `Output` into a `ByteBuffer`. `JSONEncoder()` used as default.
9093
/// - body: The handler in the form of a closure.
9194
public convenience init<Event: Decodable, Output>(
95+
logger: Logger = Logger(label: "LambdaRuntime"),
9296
decoder: JSONDecoder = JSONDecoder(),
9397
encoder: JSONEncoder = JSONEncoder(),
9498
body: sending @escaping (Event, LambdaContext) async throws -> Output
@@ -108,13 +112,15 @@ extension LambdaRuntime {
108112
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
109113
)
110114

111-
self.init(handler: handler)
115+
self.init(handler: handler, logger: logger)
112116
}
113117

114118
/// Initialize an instance with a `LambdaHandler` defined in the form of a closure **with a `Void` return type**.
119+
/// - Parameter logger: The logger to use for the runtime. Defaults to a logger with label "LambdaRuntime".
115120
/// - Parameter body: The handler in the form of a closure.
116121
/// - Parameter decoder: The decoder object that will be used to decode the incoming `ByteBuffer` event into the generic `Event` type. `JSONDecoder()` used as default.
117122
public convenience init<Event: Decodable>(
123+
logger: Logger = Logger(label: "LambdaRuntime"),
118124
decoder: JSONDecoder = JSONDecoder(),
119125
body: sending @escaping (Event, LambdaContext) async throws -> Void
120126
)
@@ -132,7 +138,7 @@ extension LambdaRuntime {
132138
handler: LambdaHandlerAdapter(handler: ClosureHandler(body: body))
133139
)
134140

135-
self.init(handler: handler)
141+
self.init(handler: handler, logger: logger)
136142
}
137143
}
138144
#endif // trait: FoundationJSONSupport

Sources/AWSLambdaRuntime/LambdaHandlers.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import NIOCore
16+
import Logging
1617

1718
/// The base handler protocol that receives a `ByteBuffer` representing the incoming event and returns the response as a `ByteBuffer` too.
1819
/// This handler protocol supports response streaming. Bytes can be streamed outwards through the ``LambdaResponseStreamWriter``
@@ -175,11 +176,15 @@ public struct ClosureHandler<Event: Decodable, Output>: LambdaHandler {
175176

176177
extension LambdaRuntime {
177178
/// Initialize an instance with a ``StreamingLambdaHandler`` in the form of a closure.
178-
/// - Parameter body: The handler in the form of a closure.
179+
/// - Parameter
180+
/// - logger: The logger to use for the runtime. Defaults to a logger with label "LambdaRuntime".
181+
/// - body: The handler in the form of a closure.
179182
public convenience init(
183+
logger: Logger = Logger(label: "LambdaRuntime"),
180184
body: @Sendable @escaping (ByteBuffer, LambdaResponseStreamWriter, LambdaContext) async throws -> Void
185+
181186
) where Handler == StreamingClosureHandler {
182-
self.init(handler: StreamingClosureHandler(body: body))
187+
self.init(handler: StreamingClosureHandler(body: body), logger: logger)
183188
}
184189

185190
/// Initialize an instance with a ``LambdaHandler`` defined in the form of a closure **with a non-`Void` return type**, an encoder, and a decoder.

0 commit comments

Comments
 (0)