Skip to content

Commit 56887c1

Browse files
author
nervenes
committed
revert logger to non optional
1 parent 85fcb6b commit 56887c1

File tree

3 files changed

+68
-42
lines changed

3 files changed

+68
-42
lines changed

Sources/ServiceLifecycle/Docs.docc/How to adopt ServiceLifecycle in applications.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,23 @@ on services with a lower index. The following example shows how this can be
6969
applied to our `BarService`.
7070

7171
```swift
72+
import ServiceLifecycle
73+
import Logging
74+
7275
@main
7376
struct Application {
77+
static let logger = Logger(label: "Application")
78+
7479
static func main() async throws {
7580
let fooService = FooServer()
7681
let barService = BarService(fooService: fooService)
7782

83+
84+
7885
let serviceGroup = ServiceGroup(
7986
// We are encoding the dependency hierarchy here by listing the fooService first
80-
services: [fooService, barService]
87+
services: [fooService, barService],
88+
logger: logger
8189
)
8290

8391
try await serviceGroup.run()
@@ -109,6 +117,9 @@ A common example of this is for applications that implement streaming
109117
behaviours.
110118

111119
```swift
120+
import ServiceLifecycle
121+
import Logging
122+
112123
struct StreamingService: Service {
113124
struct RequestStream: AsyncSequence { ... }
114125
struct ResponseWriter {
@@ -134,6 +145,8 @@ struct StreamingService: Service {
134145

135146
@main
136147
struct Application {
148+
static let logger = Logger(label: "Application")
149+
137150
static func main() async throws {
138151
let streamingService = StreamingService(streamHandler: { requestStream, responseWriter in
139152
for await request in requestStream {
@@ -143,7 +156,8 @@ struct Application {
143156

144157
let serviceGroup = ServiceGroup(
145158
services: [streamingService],
146-
gracefulShutdownSignals: [.sigterm]
159+
gracefulShutdownSignals: [.sigterm],
160+
logger: logger
147161
)
148162

149163
try await serviceGroup.run()
@@ -168,6 +182,9 @@ and what we want to do is stop the iteration. To do this we can use the
168182
`AsyncSequence`. The updated code looks like this:
169183

170184
```swift
185+
import ServiceLifecycle
186+
import Logging
187+
171188
struct StreamingService: Service {
172189
struct RequestStream: AsyncSequence { ... }
173190
struct ResponseWriter {
@@ -193,6 +210,8 @@ struct StreamingService: Service {
193210

194211
@main
195212
struct Application {
213+
static let logger = Logger(label: "Application")
214+
196215
static func main() async throws {
197216
let streamingService = StreamingService(streamHandler: { requestStream, responseWriter in
198217
for await request in requestStream.cancelOnGracefulShutdown() {
@@ -202,7 +221,8 @@ struct Application {
202221

203222
let serviceGroup = ServiceGroup(
204223
services: [streamingService],
205-
gracefulShutdownSignals: [.sigterm]
224+
gracefulShutdownSignals: [.sigterm],,
225+
logger: logger
206226
)
207227

208228
try await serviceGroup.run()
@@ -239,8 +259,13 @@ sure your telemetry service is gracefully shutdown after your HTTP server
239259
unexpectedly threw from its `run()` method. This setup could look like this:
240260

241261
```swift
262+
import ServiceLifecycle
263+
import Logging
264+
242265
@main
243266
struct Application {
267+
static let logger = Logger(label: "Application")
268+
244269
static func main() async throws {
245270
let telemetryService = TelemetryService()
246271
let httpServer = HTTPServer()
@@ -254,7 +279,8 @@ struct Application {
254279
successTerminationBehavior: .shutdownGracefully,
255280
failureTerminationBehavior: .shutdownGracefully
256281
)
257-
]
282+
],
283+
logger: logger
258284
),
259285
)
260286

0 commit comments

Comments
 (0)