Skip to content

Commit

Permalink
add support for SystemdJournal
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Jan 7, 2025
1 parent ec2c5da commit 27a31df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PlatformPackageDependencies = [
branch: "main"
),
.package(url: "https://github.com/xtremekforever/swift-systemd", from: "0.0.1"),
.package(url: "https://github.com/PADL/swift-log-systemd", from: "0.0.1"),
]

PlatformTargetDependencies = [
Expand Down Expand Up @@ -68,6 +69,7 @@ PlatformTargets = [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
.product(name: "Systemd", package: "swift-systemd", condition: .when(platforms: [.linux])),
.product(name: "SystemdJournal", package: "swift-log-systemd", condition: .when(platforms: [.linux])),
.product(
name: "SystemdLifecycle",
package: "swift-systemd",
Expand Down
11 changes: 7 additions & 4 deletions Sources/MRPDaemon/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import ArgumentParser
import Logging
import MRP
import ServiceLifecycle
#if os(Linux)
import Systemd
import SystemdJournal
import SystemdLifecycle
#endif

extension Logger.Level: ExpressibleByArgument {
public var defaultValueDescription: String {
Expand Down Expand Up @@ -125,8 +124,12 @@ private final class MRPDaemon: AsyncParsableCommand {
var logger: Logger!

func run() async throws {
LoggingSystem.bootstrap { @Sendable in
StreamLogHandler.standardError(label: $0)
if SystemdHelpers.isSystemdService {
LoggingSystem.bootstrap(SystemdJournalLogHandler.init)
} else {
LoggingSystem.bootstrap { @Sendable in
StreamLogHandler.standardError(label: $0)
}
}
logger = Logger(label: "com.padl.mrpd")
logger.logLevel = logLevel
Expand Down

0 comments on commit 27a31df

Please sign in to comment.