Skip to content

Commit 3ca1752

Browse files
committed
Fix concurrency issues (drops Swift <5.9 support)
1 parent 02bc966 commit 3ca1752

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44

5+
//let swiftSettings: [SwiftSetting] = []
6+
let swiftSettings: [SwiftSetting] = [.enableExperimentalFeature("StrictConcurrency")]
7+
58
let package = Package(
69
name: "clt-logger",
710
platforms: [
@@ -19,7 +22,7 @@ let package = Package(
1922
targets: [
2023
.target(name: "CLTLogger", dependencies: [
2124
.product(name: "Logging", package: "swift-log"),
22-
], path: "Sources"),
23-
.testTarget(name: "CLTLoggerTests", dependencies: ["CLTLogger"], path: "Tests")
25+
], path: "Sources", swiftSettings: swiftSettings),
26+
.testTarget(name: "CLTLoggerTests", dependencies: ["CLTLogger"], path: "Tests", swiftSettings: swiftSettings)
2427
]
2528
)

Sources/CLTLogger.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public struct CLTLogger : LogHandler {
5959
Newlines in the metadata themselves are always replaced by \n (and other special characters are escaped too).
6060

6161
For now there is no option to allow multilines metadata. */
62-
public enum MultilineMode {
62+
public enum MultilineMode : Sendable {
6363
/**
6464
The new lines in logs are replaced by the given value, the metadata are printed on the same line as the log.
6565

@@ -228,7 +228,7 @@ public struct CLTLogger : LogHandler {
228228
/* Do _not_ use os_unfair_lock, apparently it is bad in Swift:
229229
* <https://twitter.com/grynspan/status/1392080373752995849>.
230230
* There is OSAllocatedUnfairLock which exists and is good, but is also not available on Linux. */
231-
private static var lock = NSLock()
231+
private static let lock = NSLock()
232232

233233
private var flatMetadataCache = [String]()
234234

@@ -237,7 +237,7 @@ public struct CLTLogger : LogHandler {
237237

238238
public extension CLTLogger {
239239

240-
static var defaultConstantsByLogLevelForText: [Logger.Level: Constants] = {
240+
static let defaultConstantsByLogLevelForText: [Logger.Level: Constants] = {
241241
func addMeta(_ str: String) -> Constants {
242242
let len1 = str.count - 2
243243
let len2 = str.trimmingCharacters(in: .init(charactersIn: "[]*")).count
@@ -302,7 +302,7 @@ public extension CLTLogger {
302302
}
303303

304304
/* Terminal does not support RGB colors, so we use 255-color palette. */
305-
static var defaultConstantsByLogLevelForColors: [Logger.Level: Constants] = {
305+
static let defaultConstantsByLogLevelForColors: [Logger.Level: Constants] = {
306306
func str(_ spaces: String, _ str: String, _ mods1: [SGR.Modifier], _ mods2: [SGR.Modifier]) -> Constants {
307307
let bgColor = SGR.Modifier.reset
308308
let fgColor = SGR.Modifier.fgColorTo4BitBrightBlack

0 commit comments

Comments
 (0)