mirror of
https://github.com/apple/swift-log
synced 2026-11-24 03:47:49 +00:00
Add compile-time traits for eliminating log levels from binaries ### Motivation: Applications often know in advance which log levels will never be needed in production. For example, a production service might only need warning and above, while trace and debug levels are only useful during development. This PR introduces compile-time traits that completely eliminate unwanted log levels from binaries, achieving zero runtime overhead for disabled log statements. ### Modifications: - Added seven `MaxLogLevel*` traits - Extended benchmarks with the `MaxLogLevelWarning` suite - Added "Disable log levels during compilation" section to the best practices guide ### Result: Users can eliminate unwanted log levels at compile time by specifying traits in their `Package.swift` dependency declaration.
56 lines
1.7 KiB
Swift
56 lines
1.7 KiB
Swift
// swift-tools-version:6.0
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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"])
|
|
],
|
|
targets: [
|
|
.target(
|
|
name: "Logging",
|
|
dependencies: []
|
|
),
|
|
.testTarget(
|
|
name: "LoggingTests",
|
|
dependencies: ["Logging"]
|
|
),
|
|
]
|
|
)
|
|
|
|
for target in package.targets {
|
|
var settings = target.swiftSettings ?? []
|
|
settings.append(.enableExperimentalFeature("StrictConcurrency=complete"))
|
|
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 --- //
|