Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Apodini/swift-log-elk in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
philippzagar committed Aug 12, 2021
2 parents 4d0af16 + ffc253a commit 585e574
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,29 @@ import Logging
import LoggingELK
```

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

```swift
LoggingSystem.bootstrap { label in
LogstashLogHandler(
label: label,
hostname: "0.0.0.0",
port: 31311
)
}
// Setup of LogstashLogHandler
LogstashLogHandler.setup(hostname: "0.0.0.0", port: 31311)

// Register LogstashLogHandler in the LoggingSystem
LoggingSystem.bootstrap(LogstashLogHandler.init)
```

**Important:** Setup the `LogstashLogHandler` before registering it in the `LoggingSystem`!

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:

```swift
// Setup of LogstashLogHandler
LogstashLogHandler.setup(hostname: "0.0.0.0", port: 31311)

// Register LogHandlers in the LoggingSystem
LoggingSystem.bootstrap { label in
MultiplexLogHandler(
[
LogstashLogHandler(
label: label,
hostname: "0.0.0.0",
port: 31311
),
LogstashLogHandler(label: label),
StreamLogHandler.standardOutput(label: label)
]
)
Expand All @@ -93,19 +93,20 @@ The `LogstashLogHandler` can also be configured beyond the standard configuratio
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.

```swift
LoggingSystem.bootstrap { label in
LogstashLogHandler(
label: "logstash",
hostname: "0.0.0.0",
port: 31311,
useHTTPS: false,
eventLoopGroup: eventLoopGroup,
backgroundActivityLogger: logger,
uploadInterval: TimeAmount.seconds(3),
logStorageSize: 524_288, // 512kB
maximumTotalLogStorageSize: 2_097_152 // 2MB
)
}
// Setup of LogstashLogHandler
LogstashLogHandler.setup(
hostname: "0.0.0.0",
port: 31311,
useHTTPS: false,
eventLoopGroup: eventLoopGroup,
backgroundActivityLogger: logger,
uploadInterval: TimeAmount.seconds(5),
logStorageSize: 500_000,
maximumTotalLogStorageSize: 4_000_000
)

// Register LogstashLogHandler in the LoggingSystem
LoggingSystem.bootstrap(LogstashLogHandler.init)
```

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

0 comments on commit 585e574

Please sign in to comment.