diff --git a/Package.swift b/Package.swift index a97eb05..26083b0 100644 --- a/Package.swift +++ b/Package.swift @@ -59,24 +59,27 @@ let package = Package( ] ) -for target in package.targets { +for target in package.targets +where [.executable, .test, .regular].contains( + target.type +) { var settings = target.swiftSettings ?? [] - settings.append(.enableExperimentalFeature("StrictConcurrency=complete")) + + // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md + // Require `any` for existential types. + settings.append(.enableUpcomingFeature("ExistentialAny")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md + settings.append(.enableUpcomingFeature("MemberImportVisibility")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md + settings.append(.enableUpcomingFeature("InternalImportsByDefault")) + + // https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/ + settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault")) + + // Ensure all public types are explicitly annotated as Sendable or not Sendable. + settings.append(.unsafeFlags(["-Xfrontend", "-require-explicit-sendable"])) + target.swiftSettings = settings } - -// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // -for target in package.targets { - switch target.type { - case .regular, .test, .executable: - var settings = target.swiftSettings ?? [] - // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md - settings.append(.enableUpcomingFeature("MemberImportVisibility")) - target.swiftSettings = settings - case .macro, .plugin, .system, .binary: - () // not applicable - @unknown default: - () // we don't know what to do here, do nothing - } -} -// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 93ee785..52c258a 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -41,24 +41,24 @@ let package = Package( ] ) -for target in package.targets { +for target in package.targets +where [.executable, .test, .regular].contains( + target.type +) { var settings = target.swiftSettings ?? [] - settings.append(.enableExperimentalFeature("StrictConcurrency=complete")) + + // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md + // Require `any` for existential types. + settings.append(.enableUpcomingFeature("ExistentialAny")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md + settings.append(.enableUpcomingFeature("MemberImportVisibility")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md + settings.append(.enableUpcomingFeature("InternalImportsByDefault")) + + // https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/ + settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault")) + target.swiftSettings = settings } - -// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // -for target in package.targets { - switch target.type { - case .regular, .test, .executable: - var settings = target.swiftSettings ?? [] - // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md - settings.append(.enableUpcomingFeature("MemberImportVisibility")) - target.swiftSettings = settings - case .macro, .plugin, .system, .binary: - () // not applicable - @unknown default: - () // we don't know what to do here, do nothing - } -} -// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // diff --git a/Package@swift-6.1.swift b/Package@swift-6.1.swift new file mode 100644 index 0000000..a294b89 --- /dev/null +++ b/Package@swift-6.1.swift @@ -0,0 +1,82 @@ +// swift-tools-version:6.1 +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Logging API open source project +// +// Copyright (c) 2018-2019 Apple Inc. and the Swift Logging API project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Swift Logging API project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import PackageDescription + +let package = Package( + name: "swift-log", + products: [ + .library(name: "Logging", targets: ["Logging"]), + .library(name: "InMemoryLogging", targets: ["InMemoryLogging"]), + ], + traits: [ + .trait(name: "MaxLogLevelDebug", description: "Debug and above available (compiles out trace)"), + .trait(name: "MaxLogLevelInfo", description: "Info and above available (compiles out trace, debug)"), + .trait(name: "MaxLogLevelNotice", description: "Notice and above available (compiles out trace, debug, info)"), + .trait( + name: "MaxLogLevelWarning", + description: "Warning and above available (compiles out trace, debug, info, notice)" + ), + .trait( + name: "MaxLogLevelError", + description: "Error and above available (compiles out trace, debug, info, notice, warning)" + ), + .trait(name: "MaxLogLevelCritical", description: "Only critical available (compiles out all except critical)"), + .trait(name: "MaxLogLevelNone", description: "All logging compiled out (no log levels available)"), + + // By default, no traits are enabled (all log levels available) + .default(enabledTraits: []), + ], + targets: [ + .target( + name: "Logging", + dependencies: [] + ), + .target( + name: "InMemoryLogging", + dependencies: ["Logging"] + ), + .testTarget( + name: "LoggingTests", + dependencies: ["Logging"] + ), + .testTarget( + name: "InMemoryLoggingTests", + dependencies: ["InMemoryLogging", "Logging"] + ), + ] +) + +for target in package.targets +where [.executable, .test, .regular].contains( + target.type +) { + var settings = target.swiftSettings ?? [] + + // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md + // Require `any` for existential types. + settings.append(.enableUpcomingFeature("ExistentialAny")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md + settings.append(.enableUpcomingFeature("MemberImportVisibility")) + + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md + settings.append(.enableUpcomingFeature("InternalImportsByDefault")) + + // https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/ + settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault")) + + target.swiftSettings = settings +} diff --git a/Sources/InMemoryLogging/InMemoryLogHandler.swift b/Sources/InMemoryLogging/InMemoryLogHandler.swift index 99645c6..c142be1 100644 --- a/Sources/InMemoryLogging/InMemoryLogHandler.swift +++ b/Sources/InMemoryLogging/InMemoryLogHandler.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import Logging +public import Logging /// A custom log handler which just collects logs into memory. /// You can then retrieve an array of those log entries. diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift index bcbecce..646e318 100644 --- a/Sources/Logging/Logging.swift +++ b/Sources/Logging/Logging.swift @@ -712,7 +712,7 @@ extension Logger { /// /// The default (``StreamLogHandler``) is intended to be a convenience. /// For production applications, implement the ``LogHandler`` protocol directly, or use a community-maintained backend. -public enum LoggingSystem { +public enum LoggingSystem: Sendable { private static let _factory = FactoryBox( { label, _ in StreamLogHandler.standardError(label: label) }, violationErrorMesage: "logging system can only be initialized once per process." diff --git a/Tests/LoggingTests/LoggingTest.swift b/Tests/LoggingTests/LoggingTest.swift index 7696c63..c9e1681 100644 --- a/Tests/LoggingTests/LoggingTest.swift +++ b/Tests/LoggingTests/LoggingTest.swift @@ -443,13 +443,13 @@ struct LoggingTest { private var makeValue: (() -> String)? private var _value: String? - public init(_ makeValue: @escaping () -> String) { + init(_ makeValue: @escaping () -> String) { self.makeValue = makeValue } /// This allows caching a value in case it is accessed via an by name subscript, // rather than as part of rendering all metadata that a LoggingContext was carrying - public var value: String { + var value: String { if let f = self.makeValue { self._value = f() self.makeValue = nil @@ -459,7 +459,7 @@ struct LoggingTest { return self._value! } - public var description: String { + var description: String { "\(self.value)" } } @@ -1292,7 +1292,7 @@ struct LoggingTest { LoggingSystem.bootstrap { (label: String) in StreamLogHandler.standardOutput(label: label) } LoggingSystem.bootstrap { (label: String) in StreamLogHandler.standardError(label: label) } - // with metadata handler, explicitly, public api + // with metadata handler, explicitly, api LoggingSystem.bootstrap( { label, metadataProvider in StreamLogHandler.standardOutput(label: label, metadataProvider: metadataProvider) @@ -1337,7 +1337,7 @@ struct LoggingTest { } extension Logger { - public func error( + func error( error: any Error, metadata: @autoclosure () -> Logger.Metadata? = nil, file: String = #fileID, diff --git a/Tests/LoggingTests/MetadataProviderTest.swift b/Tests/LoggingTests/MetadataProviderTest.swift index 7ce7e3e..30bb3ce 100644 --- a/Tests/LoggingTests/MetadataProviderTest.swift +++ b/Tests/LoggingTests/MetadataProviderTest.swift @@ -74,13 +74,13 @@ extension Logger.MetadataProvider { } } -public struct LogHandlerThatDidNotImplementMetadataProviders: LogHandler { +struct LogHandlerThatDidNotImplementMetadataProviders: LogHandler { let testLogging: TestLogging init(testLogging: TestLogging) { self.testLogging = testLogging } - public subscript(metadataKey _: String) -> Logging.Logger.Metadata.Value? { + subscript(metadataKey _: String) -> Logging.Logger.Metadata.Value? { get { nil } @@ -89,11 +89,11 @@ public struct LogHandlerThatDidNotImplementMetadataProviders: LogHandler { } } - public var metadata: Logging.Logger.Metadata = [:] + var metadata: Logging.Logger.Metadata = [:] - public var logLevel: Logging.Logger.Level = .trace + var logLevel: Logging.Logger.Level = .trace - public func log( + func log( level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, @@ -114,13 +114,13 @@ public struct LogHandlerThatDidNotImplementMetadataProviders: LogHandler { } } -public struct LogHandlerThatDidImplementMetadataProviders: LogHandler { +struct LogHandlerThatDidImplementMetadataProviders: LogHandler { let testLogging: TestLogging init(testLogging: TestLogging) { self.testLogging = testLogging } - public subscript(metadataKey _: String) -> Logging.Logger.Metadata.Value? { + subscript(metadataKey _: String) -> Logging.Logger.Metadata.Value? { get { nil } @@ -129,13 +129,13 @@ public struct LogHandlerThatDidImplementMetadataProviders: LogHandler { } } - public var metadata: Logging.Logger.Metadata = [:] + var metadata: Logging.Logger.Metadata = [:] - public var logLevel: Logging.Logger.Level = .trace + var logLevel: Logging.Logger.Level = .trace - public var metadataProvider: Logger.MetadataProvider? + var metadataProvider: Logger.MetadataProvider? - public func log( + func log( level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, diff --git a/Tests/LoggingTests/TestLogger.swift b/Tests/LoggingTests/TestLogger.swift index fc77249..e794e73 100644 --- a/Tests/LoggingTests/TestLogger.swift +++ b/Tests/LoggingTests/TestLogger.swift @@ -54,7 +54,7 @@ internal struct TestLogHandler: LogHandler { private var logger: Logger // the actual logger let label: String - public var metadataProvider: Logger.MetadataProvider? + var metadataProvider: Logger.MetadataProvider? init(label: String, config: Config, recorder: Recorder, metadataProvider: Logger.MetadataProvider?) { self.label = label @@ -125,7 +125,7 @@ internal struct TestLogHandler: LogHandler { } } - public var metadata: Logger.Metadata { + var metadata: Logger.Metadata { get { self._metadata } @@ -303,15 +303,15 @@ extension History { } /// MDC stands for Mapped Diagnostic Context -public class MDC { +class MDC { private let lock = NSLock() private var storage = [Int: Logger.Metadata]() - public static let global = MDC() + static let global = MDC() private init() {} - public subscript(metadataKey: String) -> Logger.Metadata.Value? { + subscript(metadataKey: String) -> Logger.Metadata.Value? { get { self.lock.withLock { self.storage[self.threadId]?[metadataKey] @@ -327,19 +327,19 @@ public class MDC { } } - public var metadata: Logger.Metadata { + var metadata: Logger.Metadata { self.lock.withLock { self.storage[self.threadId] ?? [:] } } - public func clear() { + func clear() { self.lock.withLock { _ = self.storage.removeValue(forKey: self.threadId) } } - public func with(metadata: Logger.Metadata, _ body: () throws -> Void) rethrows { + func with(metadata: Logger.Metadata, _ body: () throws -> Void) rethrows { for (key, value) in metadata { self[key] = value } @@ -351,7 +351,7 @@ public class MDC { try body() } - public func with(metadata: Logger.Metadata, _ body: () throws -> T) rethrows -> T { + func with(metadata: Logger.Metadata, _ body: () throws -> T) rethrows -> T { for (key, value) in metadata { self[key] = value } @@ -389,13 +389,13 @@ internal struct TestLibrary: Sendable { private let logger = Logger(label: "TestLibrary") private let queue = DispatchQueue(label: "TestLibrary") - public init() {} + init() {} - public func doSomething() { + func doSomething() { self.logger.info("TestLibrary::doSomething") } - public func doSomethingAsync(completion: @escaping @Sendable () -> Void) { + func doSomethingAsync(completion: @escaping @Sendable () -> Void) { // libraries that use global loggers and async, need to make sure they propagate the // logging metadata when creating a new thread let metadata = MDC.global.metadata