Skip to content

Commit

Permalink
fix: don't call openlog()
Browse files Browse the repository at this point in the history
`openlog()` may retain the `ident` internally, so we can't pass it the
label's raw buffer.  Also, it's not necessary to call `openlog()`
multiple times which would happen when it's called from the
`LogHandler`'s initialization.

Instead, pass the logger label in the log message.
ianpartridge committed May 1, 2019
1 parent ce72399 commit 93e9cb6
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions Sources/LoggingSyslog/SyslogLogHandler.swift
Original file line number Diff line number Diff line change
@@ -8,9 +8,6 @@ public struct SyslogLogHandler: LogHandler {
/// Create a `SyslogLogHandler`.
public init(label: String) {
self.label = label
label.withCString {
openlog($0, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0)
}
}

public let label: String
@@ -35,7 +32,7 @@ public struct SyslogLogHandler: LogHandler {
? self.prettyMetadata
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))

let message = "\(prettyMetadata.map { " \($0)" } ?? "") \(message)"
let message = "\(self.label): \(prettyMetadata.map { " \($0)" } ?? "") \(message)"
message.withCString {
syslog_helper(level.asSyslogPriority(), $0)
}

0 comments on commit 93e9cb6

Please sign in to comment.