From fb800a495f8ee7d46796333d956dd4d92c14da40 Mon Sep 17 00:00:00 2001 From: Timo <38291523+lovetodream@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:42:57 +0100 Subject: [PATCH] feat: add support for additional platforms --- Package.swift | 17 +++++------------ Sources/LoggingLoki/LokiLogHandler.swift | 2 +- Sources/LoggingLoki/LokiStream.swift | 2 ++ 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index a85c9de..aee6bbc 100644 --- a/Package.swift +++ b/Package.swift @@ -1,15 +1,11 @@ // swift-tools-version: 5.7 -// The swift-tools-version declares the minimum version of Swift required to build this package. - import PackageDescription let package = Package( name: "swift-log-loki", - platforms: [.macOS(.v11)], + platforms: [.macOS(.v11), .iOS(.v14), .tvOS(.v14), .watchOS(.v7)], products: [ - .library( - name: "LoggingLoki", - targets: ["LoggingLoki"]), + .library(name: "LoggingLoki", targets: ["LoggingLoki"]), ], dependencies: [ .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"), @@ -18,17 +14,14 @@ let package = Package( .package(url: "https://github.com/lovetodream/swift-snappy", from: "1.0.0"), ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "LoggingLoki", dependencies: [ .product(name: "Logging", package: "swift-log"), .product(name: "SwiftProtobuf", package: "swift-protobuf"), .product(name: "Snappy", package: "swift-snappy"), - ]), - .testTarget( - name: "LoggingLokiTests", - dependencies: ["LoggingLoki"]), + ] + ), + .testTarget(name: "LoggingLokiTests", dependencies: ["LoggingLoki"]), ] ) diff --git a/Sources/LoggingLoki/LokiLogHandler.swift b/Sources/LoggingLoki/LokiLogHandler.swift index 76f9ba2..25377f4 100644 --- a/Sources/LoggingLoki/LokiLogHandler.swift +++ b/Sources/LoggingLoki/LokiLogHandler.swift @@ -34,7 +34,7 @@ public struct LokiLogHandler: LogHandler, Sendable { #if os(Linux) // this needs to be explicitly checked, otherwise the build will fail on linux self.lokiURL = lokiURL.appendingPathComponent("/loki/api/v1/push") #else - if #available(macOS 13.0, *) { + if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { self.lokiURL = lokiURL.appending(path: "/loki/api/v1/push") } else { self.lokiURL = lokiURL.appendingPathComponent("/loki/api/v1/push") diff --git a/Sources/LoggingLoki/LokiStream.swift b/Sources/LoggingLoki/LokiStream.swift index 3b2f256..5817064 100644 --- a/Sources/LoggingLoki/LokiStream.swift +++ b/Sources/LoggingLoki/LokiStream.swift @@ -11,7 +11,9 @@ struct LokiStream: Encodable, Sendable { let formatter = NumberFormatter() formatter.numberStyle = .decimal formatter.groupingSeparator = "" + #if os(macOS) || !canImport(Darwin) formatter.thousandSeparator = "" + #endif let timestamp = Int64(log.timestamp.timeIntervalSince1970 * 1_000_000_000) as NSNumber guard let formattedTimestamp = formatter.string(from: timestamp) else { return nil