Skip to content

Commit 585e574

Browse files
committed
Merge branch 'develop' of https://github.com/Apodini/swift-log-elk into develop
2 parents 4d0af16 + ffc253a commit 585e574

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,29 @@ import Logging
5757
import LoggingELK
5858
```
5959

60-
Create the `LogstashLogHandler` with the appropriate configuration and register the to be used logging backend once (!) during the lifetime of the application:
60+
Setup the `LogstashLogHandler` with the appropriate configuration and register the to be used logging backend once (!) during the lifetime of the application:
6161

6262
```swift
63-
LoggingSystem.bootstrap { label in
64-
LogstashLogHandler(
65-
label: label,
66-
hostname: "0.0.0.0",
67-
port: 31311
68-
)
69-
}
63+
// Setup of LogstashLogHandler
64+
LogstashLogHandler.setup(hostname: "0.0.0.0", port: 31311)
65+
66+
// Register LogstashLogHandler in the LoggingSystem
67+
LoggingSystem.bootstrap(LogstashLogHandler.init)
7068
```
7169

70+
**Important:** Setup the `LogstashLogHandler` before registering it in the `LoggingSystem`!
71+
7272
Furthermore, it's possible to register multiple logging backends. An option would be to send the logs to Logstash as well as print them to console:
7373

7474
```swift
75+
// Setup of LogstashLogHandler
76+
LogstashLogHandler.setup(hostname: "0.0.0.0", port: 31311)
77+
78+
// Register LogHandlers in the LoggingSystem
7579
LoggingSystem.bootstrap { label in
7680
MultiplexLogHandler(
7781
[
78-
LogstashLogHandler(
79-
label: label,
80-
hostname: "0.0.0.0",
81-
port: 31311
82-
),
82+
LogstashLogHandler(label: label),
8383
StreamLogHandler.standardOutput(label: label)
8484
]
8585
)
@@ -93,19 +93,20 @@ The `LogstashLogHandler` can also be configured beyond the standard configuratio
9393
Why at least twice as large? The process of allocating temporary buffers could possibly be repeated, if the log storage runs full during uploading of "old" log data. A possible scenario is an environment, where the network conncection to Logstash is really slow and therefore the uploading takes long. This process could repeat itself over and over again until the `maximumTotalLogStorageSize` is reached. Then, a new logging call blocks until enought memory space is available again, achieved through a partial completed uploading of log data, resulting in freed temporary buffers. In practice, approaching the `maximumTotalLogStorageSize` should basically never happen, except in very resource restricted environments.
9494

9595
```swift
96-
LoggingSystem.bootstrap { label in
97-
LogstashLogHandler(
98-
label: "logstash",
99-
hostname: "0.0.0.0",
100-
port: 31311,
101-
useHTTPS: false,
102-
eventLoopGroup: eventLoopGroup,
103-
backgroundActivityLogger: logger,
104-
uploadInterval: TimeAmount.seconds(3),
105-
logStorageSize: 524_288, // 512kB
106-
maximumTotalLogStorageSize: 2_097_152 // 2MB
107-
)
108-
}
96+
// Setup of LogstashLogHandler
97+
LogstashLogHandler.setup(
98+
hostname: "0.0.0.0",
99+
port: 31311,
100+
useHTTPS: false,
101+
eventLoopGroup: eventLoopGroup,
102+
backgroundActivityLogger: logger,
103+
uploadInterval: TimeAmount.seconds(5),
104+
logStorageSize: 500_000,
105+
maximumTotalLogStorageSize: 4_000_000
106+
)
107+
108+
// Register LogstashLogHandler in the LoggingSystem
109+
LoggingSystem.bootstrap(LogstashLogHandler.init)
109110
```
110111

111112
Now that the setup of the `LogstashLogHandler` is completed, you can use `SwiftLog` as usual (also with metadata etc.).

0 commit comments

Comments
 (0)