mirror of
https://github.com/apple/swift-log
synced 2026-11-22 03:40:39 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cb486020e | ||
|
|
b3a6373077 | ||
|
|
4bcd3dfb11 | ||
|
|
7adcf9aa15 | ||
|
|
f5312694b3 | ||
|
|
6553ef5893 | ||
|
|
11e749ea6d | ||
|
|
d16e216341 | ||
|
|
0f170b4764 | ||
|
|
23517234d5 | ||
|
|
c7dcb55fb9 | ||
|
|
ebb05e0317 | ||
|
|
b1617b3c0c |
No files matched your search
+1
-4
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.6
|
||||
// swift-tools-version:5.8
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Logging API open source project
|
||||
@@ -20,9 +20,6 @@ let package = Package(
|
||||
products: [
|
||||
.library(name: "Logging", targets: ["Logging"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "Logging",
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// swift-tools-version:5.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"]),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "Logging",
|
||||
dependencies: []
|
||||
),
|
||||
.testTarget(
|
||||
name: "LoggingTests",
|
||||
dependencies: ["Logging"]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
// swift-tools-version:5.2
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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"]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
// swift-tools-version:5.3
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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"]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
// swift-tools-version:5.4
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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"]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -1,33 +0,0 @@
|
||||
// swift-tools-version:5.5
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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"]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -10,7 +10,7 @@ If you have a server-side Swift application, or maybe a cross-platform (for exam
|
||||
|
||||
#### Adding the dependency
|
||||
|
||||
`SwiftLog` is designed for Swift 5. To depend on the logging API package, you need to declare your dependency in your `Package.swift`:
|
||||
`SwiftLog` is designed for Swift 5.8 and later. To depend on the logging API package, you need to declare your dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
|
||||
@@ -19,10 +19,6 @@ If you have a server-side Swift application, or maybe a cross-platform (for exam
|
||||
and to your application/library target, add `"Logging"` to your `dependencies`, e.g. like this:
|
||||
|
||||
```swift
|
||||
// Target syntax for Swift up to version 5.1
|
||||
.target(name: "BestExampleApp", dependencies: ["Logging"]),
|
||||
|
||||
// Target for Swift 5.2
|
||||
.target(name: "BestExampleApp", dependencies: [
|
||||
.product(name: "Logging", package: "swift-log")
|
||||
],
|
||||
@@ -81,13 +77,14 @@ You can choose from one of the following backends to consume your logs. If you a
|
||||
| [google/SwiftLogFireCloud](https://github.com/google/swiftlogfirecloud) | a logging backend for time series logging which pushes logs as flat files to Firebase Cloud Storage. |
|
||||
| [crspybits/swift-log-file](https://github.com/crspybits/swift-log-file) | a simple local file logger (using `Foundation` `FileManager`) |
|
||||
| [sushichop/Puppy](https://github.com/sushichop/Puppy) | a logging backend that supports multiple transports(console, file, syslog, etc.) and has the feature with formatting and file log rotation |
|
||||
| [luoxiu/LogDog](https://github.com/luoxiu/LogDog) | user-friendly logging with sinks and appenders |
|
||||
| [ShivaHuang/swift-log-SwiftyBeaver](https://github.com/ShivaHuang/swift-log-SwiftyBeaver) | a logging backend for printing colored logging to Xcode console / file, or sending encrypted logging to [SwiftyBeaver](https://swiftybeaver.com) platform. |
|
||||
| [Apodini/swift-log-elk](https://github.com/Apodini/swift-log-elk) | a logging backend that formats, caches and sends log data to [elastic/logstash](https://github.com/elastic/logstash) |
|
||||
| [binaryscraping/swift-log-supabase](https://github.com/binaryscraping/swift-log-supabase) | a logging backend that sends log entries to [Supabase](https://github.com/supabase/supabase). |
|
||||
| [kiliankoe/swift-log-matrix](https://swiftpackageindex.com/kiliankoe/swift-log-matrix) | a logging backend for sending logs directly to a [Matrix](https://matrix.org) room |
|
||||
| [DiscordBM/DiscordLogger](https://github.com/DiscordBM/DiscordLogger) | a Discord logging implementation to send your logs over to a Discord channel in a good-looking manner and with a lot of configuration options including the ability to send only a few important log-levels such as `warning`/`error`/`critical`. |
|
||||
| [CocoaLumberjack](https://github.com/CocoaLumberjack/CocoaLumberjack) | a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS, which includes a logging backend for swift-log. |
|
||||
| [rwbutler/swift-log-ecs](https://github.com/rwbutler/swift-log-ecs) | a logging backend for logging in [ECS Log format](https://www.elastic.co/guide/en/ecs-logging/overview/current/intro.html). Compatible with [Vapor](https://github.com/vapor/vapor) and allows chaining of multiple LogHandlers. |
|
||||
| [ShipBook/swift-log-**shipbook**](https://github.com/ShipBook/swift-log-shipbook) | a logging backend that sends log entries to [Shipbook](https://www.shipbook.io) - Shipbook gives you the power to remotely gather, search and analyze your user logs and exceptions in the cloud, on a per-user & session basis. |
|
||||
| Your library? | [Get in touch!](https://forums.swift.org/c/server) |
|
||||
|
||||
## What is an API package?
|
||||
@@ -220,4 +217,3 @@ This logging API was designed with the contributors to the Swift on Server commu
|
||||
- [log levels](https://forums.swift.org/t/logging-levels-for-swifts-server-side-logging-apis-and-new-os-log-apis/20365)
|
||||
|
||||
[api-docs]: https://apple.github.io/swift-log/docs/current/Logging/Structs/Logger.html
|
||||
|
||||
@@ -46,7 +46,7 @@ import Musl
|
||||
/// of lock is safe to use with `libpthread`-based threading models, such as the
|
||||
/// one used by NIO. On Windows, the lock is based on the substantially similar
|
||||
/// `SRWLOCK` type.
|
||||
internal final class Lock {
|
||||
internal final class Lock: @unchecked Sendable {
|
||||
#if canImport(WASILibc)
|
||||
// WASILibc is single threaded, provides no locks
|
||||
#elseif os(Windows)
|
||||
@@ -148,7 +148,7 @@ extension Lock {
|
||||
/// of lock is safe to use with `libpthread`-based threading models, such as the
|
||||
/// one used by NIO. On Windows, the lock is based on the substantially similar
|
||||
/// `SRWLOCK` type.
|
||||
internal final class ReadWriteLock {
|
||||
internal final class ReadWriteLock: @unchecked Sendable {
|
||||
#if canImport(WASILibc)
|
||||
// WASILibc is single threaded, provides no locks
|
||||
#elseif os(Windows)
|
||||
@@ -189,7 +189,7 @@ internal final class ReadWriteLock {
|
||||
///
|
||||
/// Whenever possible, consider using `withReaderLock` instead of this
|
||||
/// method and `unlock`, to simplify lock handling.
|
||||
public func lockRead() {
|
||||
fileprivate func lockRead() {
|
||||
#if canImport(WASILibc)
|
||||
// WASILibc is single threaded, provides no locks
|
||||
#elseif os(Windows)
|
||||
@@ -205,7 +205,7 @@ internal final class ReadWriteLock {
|
||||
///
|
||||
/// Whenever possible, consider using `withWriterLock` instead of this
|
||||
/// method and `unlock`, to simplify lock handling.
|
||||
public func lockWrite() {
|
||||
fileprivate func lockWrite() {
|
||||
#if canImport(WASILibc)
|
||||
// WASILibc is single threaded, provides no locks
|
||||
#elseif os(Windows)
|
||||
@@ -222,7 +222,7 @@ internal final class ReadWriteLock {
|
||||
/// Whenever possible, consider using `withReaderLock` and `withWriterLock`
|
||||
/// instead of this method and `lockRead` and `lockWrite`, to simplify lock
|
||||
/// handling.
|
||||
public func unlock() {
|
||||
fileprivate func unlock() {
|
||||
#if canImport(WASILibc)
|
||||
// WASILibc is single threaded, provides no locks
|
||||
#elseif os(Windows)
|
||||
|
||||
@@ -212,8 +212,4 @@ extension LogHandler {
|
||||
|
||||
// MARK: - Sendable support helpers
|
||||
|
||||
#if compiler(>=5.6)
|
||||
@preconcurrency public protocol _SwiftLogSendableLogHandler: Sendable {}
|
||||
#else
|
||||
public protocol _SwiftLogSendableLogHandler {}
|
||||
#endif
|
||||
+195
-338
File diff suppressed because it is too large.
Load diff
@@ -26,11 +26,7 @@ import WASILibc
|
||||
#error("Unsupported runtime")
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.6)
|
||||
@preconcurrency protocol _SwiftLogSendable: Sendable {}
|
||||
#else
|
||||
protocol _SwiftLogSendable {}
|
||||
#endif
|
||||
|
||||
extension Logger {
|
||||
/// A `MetadataProvider` is used to automatically inject runtime-generated metadata
|
||||
@@ -61,28 +57,16 @@ extension Logger {
|
||||
/// if necessary.
|
||||
public struct MetadataProvider: _SwiftLogSendable {
|
||||
/// Provide ``Logger.Metadata`` from current context.
|
||||
#if swift(>=5.5) && canImport(_Concurrency) // we could instead typealias the function type, but it was requested that we avoid this for better developer experience
|
||||
@usableFromInline
|
||||
internal let _provideMetadata: @Sendable() -> Metadata
|
||||
#else
|
||||
@usableFromInline
|
||||
internal let _provideMetadata: () -> Metadata
|
||||
#endif
|
||||
|
||||
/// Create a new `MetadataProvider`.
|
||||
///
|
||||
/// - Parameter provideMetadata: A closure extracting metadata from the current execution context.
|
||||
#if swift(>=5.5) && canImport(_Concurrency)
|
||||
public init(_ provideMetadata: @escaping @Sendable() -> Metadata) {
|
||||
self._provideMetadata = provideMetadata
|
||||
}
|
||||
|
||||
#else
|
||||
public init(_ provideMetadata: @escaping () -> Metadata) {
|
||||
self._provideMetadata = provideMetadata
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Invoke the metadata provider and return the generated contextual ``Logger/Metadata``.
|
||||
public func get() -> Metadata {
|
||||
return self._provideMetadata()
|
||||
|
||||
@@ -1,36 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// LinuxMain.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
#if os(Linux) || os(FreeBSD) || os(Windows) || os(Android)
|
||||
@testable import LoggingTests
|
||||
|
||||
XCTMain([
|
||||
testCase(CompatibilityTest.allTests),
|
||||
testCase(GlobalLoggerTest.allTests),
|
||||
testCase(LocalLoggerTest.allTests),
|
||||
testCase(LoggingTest.allTests),
|
||||
testCase(MDCTest.allTests),
|
||||
testCase(MetadataProviderTest.allTests),
|
||||
])
|
||||
#endif
|
||||
@@ -1,31 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// CompatibilityTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension CompatibilityTest {
|
||||
static var allTests: [(String, (CompatibilityTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("testAllLogLevelsWorkWithOldSchoolLogHandlerWorks", testAllLogLevelsWorkWithOldSchoolLogHandlerWorks),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,11 @@
|
||||
import XCTest
|
||||
|
||||
final class CompatibilityTest: XCTestCase {
|
||||
@available(*, deprecated, message: "Testing deprecated functionality")
|
||||
func testAllLogLevelsWorkWithOldSchoolLogHandlerWorks() {
|
||||
let testLogging = OldSchoolTestLogging()
|
||||
|
||||
var logger = Logger(label: "\(#function)", factory: testLogging.make)
|
||||
var logger = Logger(label: "\(#function)", factory: { testLogging.make(label: $0) })
|
||||
logger.logLevel = .trace
|
||||
|
||||
logger.trace("yes: trace")
|
||||
@@ -45,7 +46,8 @@ private struct OldSchoolTestLogging {
|
||||
private let _config = Config() // shared among loggers
|
||||
private let recorder = Recorder() // shared among loggers
|
||||
|
||||
func make(label: String) -> LogHandler {
|
||||
@available(*, deprecated, message: "Testing deprecated functionality")
|
||||
func make(label: String) -> any LogHandler {
|
||||
return OldSchoolLogHandler(label: label,
|
||||
config: self.config,
|
||||
recorder: self.recorder,
|
||||
@@ -54,15 +56,16 @@ private struct OldSchoolTestLogging {
|
||||
}
|
||||
|
||||
var config: Config { return self._config }
|
||||
var history: History { return self.recorder }
|
||||
var history: some History { return self.recorder }
|
||||
}
|
||||
|
||||
@available(*, deprecated, message: "Testing deprecated functionality")
|
||||
private struct OldSchoolLogHandler: LogHandler {
|
||||
var label: String
|
||||
let config: Config
|
||||
let recorder: Recorder
|
||||
|
||||
func make(label: String) -> LogHandler {
|
||||
func make(label: String) -> some LogHandler {
|
||||
return TestLogHandler(label: label, config: self.config, recorder: self.recorder)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// GlobalLoggingTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension GlobalLoggerTest {
|
||||
static var allTests: [(String, (GlobalLoggerTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("test1", test1),
|
||||
("test2", test2),
|
||||
("test3", test3),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,17 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
@testable import Logging
|
||||
import XCTest
|
||||
#if compiler(>=6.0) || canImport(Darwin)
|
||||
import Dispatch
|
||||
#else
|
||||
@preconcurrency import Dispatch
|
||||
#endif
|
||||
|
||||
class GlobalLoggerTest: XCTestCase {
|
||||
func test1() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// change test logging config to log traces and above
|
||||
logging.config.set(value: Logger.Level.debug)
|
||||
@@ -45,7 +50,7 @@ class GlobalLoggerTest: XCTestCase {
|
||||
func test2() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// change test logging config to log errors and above
|
||||
logging.config.set(value: Logger.Level.error)
|
||||
@@ -72,7 +77,7 @@ class GlobalLoggerTest: XCTestCase {
|
||||
func test3() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// change test logging config
|
||||
logging.config.set(value: .warning)
|
||||
|
||||
@@ -1,32 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// LocalLoggingTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension LocalLoggerTest {
|
||||
static var allTests: [(String, (LocalLoggerTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("test1", test1),
|
||||
("test2", test2),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,17 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
@testable import Logging
|
||||
import XCTest
|
||||
#if compiler(>=6.0) || canImport(Darwin)
|
||||
import Dispatch
|
||||
#else
|
||||
@preconcurrency import Dispatch
|
||||
#endif
|
||||
|
||||
class LocalLoggerTest: XCTestCase {
|
||||
func test1() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// change test logging config to log traces and above
|
||||
logging.config.set(value: Logger.Level.debug)
|
||||
@@ -46,7 +51,7 @@ class LocalLoggerTest: XCTestCase {
|
||||
func test2() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// change test logging config to log errors and above
|
||||
logging.config.set(value: Logger.Level.error)
|
||||
|
||||
@@ -1,68 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// LoggingTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension LoggingTest {
|
||||
static var allTests: [(String, (LoggingTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("testAutoclosure", testAutoclosure),
|
||||
("testMultiplex", testMultiplex),
|
||||
("testMultiplexLogHandlerWithVariousLogLevels", testMultiplexLogHandlerWithVariousLogLevels),
|
||||
("testMultiplexLogHandlerNeedNotMaterializeValuesMultipleTimes", testMultiplexLogHandlerNeedNotMaterializeValuesMultipleTimes),
|
||||
("testMultiplexLogHandlerMetadata_settingMetadataThroughToUnderlyingHandlers", testMultiplexLogHandlerMetadata_settingMetadataThroughToUnderlyingHandlers),
|
||||
("testMultiplexLogHandlerMetadata_readingHandlerMetadata", testMultiplexLogHandlerMetadata_readingHandlerMetadata),
|
||||
("testMultiplexMetadataProviderSet", testMultiplexMetadataProviderSet),
|
||||
("testMultiplexMetadataProviderExtract", testMultiplexMetadataProviderExtract),
|
||||
("testDictionaryMetadata", testDictionaryMetadata),
|
||||
("testListMetadata", testListMetadata),
|
||||
("testStringConvertibleMetadata", testStringConvertibleMetadata),
|
||||
("testAutoClosuresAreNotForcedUnlessNeeded", testAutoClosuresAreNotForcedUnlessNeeded),
|
||||
("testLocalMetadata", testLocalMetadata),
|
||||
("testCustomFactory", testCustomFactory),
|
||||
("testAllLogLevelsExceptCriticalCanBeBlocked", testAllLogLevelsExceptCriticalCanBeBlocked),
|
||||
("testAllLogLevelsWork", testAllLogLevelsWork),
|
||||
("testAllLogLevelByFunctionRefWithSource", testAllLogLevelByFunctionRefWithSource),
|
||||
("testAllLogLevelByFunctionRefWithoutSource", testAllLogLevelByFunctionRefWithoutSource),
|
||||
("testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts", testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts),
|
||||
("testLogMessageWithStringInterpolation", testLogMessageWithStringInterpolation),
|
||||
("testLoggingAString", testLoggingAString),
|
||||
("testMultiplexMetadataProviderMergesInSpecifiedOrder", testMultiplexMetadataProviderMergesInSpecifiedOrder),
|
||||
("testLoggerWithoutFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider", testLoggerWithoutFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider),
|
||||
("testLoggerWithPredefinedLibraryMetadataProvider", testLoggerWithPredefinedLibraryMetadataProvider),
|
||||
("testLoggerWithFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider", testLoggerWithFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider),
|
||||
("testMultiplexerIsValue", testMultiplexerIsValue),
|
||||
("testLoggerWithGlobalOverride", testLoggerWithGlobalOverride),
|
||||
("testLogLevelCases", testLogLevelCases),
|
||||
("testLogLevelOrdering", testLogLevelOrdering),
|
||||
("testStreamLogHandlerWritesToAStream", testStreamLogHandlerWritesToAStream),
|
||||
("testStreamLogHandlerOutputFormat", testStreamLogHandlerOutputFormat),
|
||||
("testStreamLogHandlerOutputFormatWithMetaData", testStreamLogHandlerOutputFormatWithMetaData),
|
||||
("testStreamLogHandlerOutputFormatWithOrderedMetadata", testStreamLogHandlerOutputFormatWithOrderedMetadata),
|
||||
("testStreamLogHandlerWritesIncludeMetadataProviderMetadata", testStreamLogHandlerWritesIncludeMetadataProviderMetadata),
|
||||
("testStdioOutputStreamWrite", testStdioOutputStreamWrite),
|
||||
("testStdioOutputStreamFlush", testStdioOutputStreamFlush),
|
||||
("testOverloadingError", testOverloadingError),
|
||||
("testCompileInitializeStandardStreamLogHandlersWithMetadataProviders", testCompileInitializeStandardStreamLogHandlersWithMetadataProviders),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,25 @@ import WinSDK
|
||||
import Glibc
|
||||
#endif
|
||||
|
||||
private extension LogHandler {
|
||||
func with(logLevel: Logger.Level) -> any LogHandler {
|
||||
var result = self
|
||||
result.logLevel = logLevel
|
||||
return result
|
||||
}
|
||||
|
||||
func withMetadata(_ key: String, _ value: Logger.MetadataValue) -> any LogHandler {
|
||||
var result = self
|
||||
result.metadata[key] = value
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class LoggingTest: XCTestCase {
|
||||
func testAutoclosure() throws {
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "test")
|
||||
logger.logLevel = .info
|
||||
@@ -80,11 +94,8 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var logger1 = logging1.make(label: "1")
|
||||
logger1.logLevel = .info
|
||||
|
||||
var logger2 = logging2.make(label: "2")
|
||||
logger2.logLevel = .debug
|
||||
let logger1 = logging1.make(label: "1").with(logLevel: .info)
|
||||
let logger2 = logging2.make(label: "2").with(logLevel: .debug)
|
||||
|
||||
LoggingSystem.bootstrapInternal { _ in
|
||||
MultiplexLogHandler([logger1, logger2])
|
||||
@@ -111,11 +122,8 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var logger1 = logging1.make(label: "1")
|
||||
logger1.logLevel = .info
|
||||
|
||||
var logger2 = logging2.make(label: "2")
|
||||
logger2.logLevel = .info
|
||||
let logger1 = logging1.make(label: "1").with(logLevel: .info)
|
||||
let logger2 = logging2.make(label: "2").with(logLevel: .info)
|
||||
|
||||
LoggingSystem.bootstrapInternal { _ in
|
||||
MultiplexLogHandler([logger1, logger2])
|
||||
@@ -147,12 +155,12 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var logger1 = logging1.make(label: "1")
|
||||
logger1.metadata["one"] = "111"
|
||||
logger1.metadata["in"] = "in-1"
|
||||
var logger2 = logging2.make(label: "2")
|
||||
logger2.metadata["two"] = "222"
|
||||
logger2.metadata["in"] = "in-2"
|
||||
let logger1 = logging1.make(label: "1")
|
||||
.withMetadata("one", "111")
|
||||
.withMetadata("in", "in-1")
|
||||
let logger2 = logging2.make(label: "2")
|
||||
.withMetadata("two", "222")
|
||||
.withMetadata("in", "in-2")
|
||||
|
||||
LoggingSystem.bootstrapInternal { _ in
|
||||
MultiplexLogHandler([logger1, logger2])
|
||||
@@ -204,12 +212,12 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var logger1 = logging1.make(label: "1")
|
||||
logger1.metadata["one"] = "111"
|
||||
logger1.metadata["in"] = "in-1"
|
||||
var logger2 = logging2.make(label: "2")
|
||||
logger2.metadata["two"] = "222"
|
||||
logger2.metadata["in"] = "in-2"
|
||||
let logger1 = logging1.make(label: "1")
|
||||
.withMetadata("one", "111")
|
||||
.withMetadata("in", "in-1")
|
||||
let logger2 = logging2.make(label: "2")
|
||||
.withMetadata("two", "222")
|
||||
.withMetadata("in", "in-2")
|
||||
|
||||
LoggingSystem.bootstrapInternal { _ in
|
||||
MultiplexLogHandler([logger1, logger2])
|
||||
@@ -228,20 +236,26 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var handler1 = logging1.make(label: "1")
|
||||
handler1.metadata["one"] = "111"
|
||||
handler1.metadata["in"] = "in-1"
|
||||
handler1.metadataProvider = .constant([
|
||||
"provider-1": "provided-111",
|
||||
"provider-overlap": "provided-111",
|
||||
])
|
||||
var handler2 = logging2.make(label: "2")
|
||||
handler2.metadata["two"] = "222"
|
||||
handler2.metadata["in"] = "in-2"
|
||||
handler2.metadataProvider = .constant([
|
||||
"provider-2": "provided-222",
|
||||
"provider-overlap": "provided-222",
|
||||
])
|
||||
let handler1 = {
|
||||
var handler1 = logging1.make(label: "1")
|
||||
handler1.metadata["one"] = "111"
|
||||
handler1.metadata["in"] = "in-1"
|
||||
handler1.metadataProvider = .constant([
|
||||
"provider-1": "provided-111",
|
||||
"provider-overlap": "provided-111",
|
||||
])
|
||||
return handler1
|
||||
}()
|
||||
let handler2 = {
|
||||
var handler2 = logging2.make(label: "2")
|
||||
handler2.metadata["two"] = "222"
|
||||
handler2.metadata["in"] = "in-2"
|
||||
handler2.metadataProvider = .constant([
|
||||
"provider-2": "provided-222",
|
||||
"provider-overlap": "provided-222",
|
||||
])
|
||||
return handler2
|
||||
}()
|
||||
|
||||
LoggingSystem.bootstrapInternal { _ in
|
||||
MultiplexLogHandler([handler1, handler2])
|
||||
@@ -268,18 +282,24 @@ class LoggingTest: XCTestCase {
|
||||
let logging1 = TestLogging()
|
||||
let logging2 = TestLogging()
|
||||
|
||||
var handler1 = logging1.make(label: "1")
|
||||
handler1.metadataProvider = .constant([
|
||||
"provider-1": "provided-111",
|
||||
"provider-overlap": "provided-111",
|
||||
])
|
||||
var handler2 = logging2.make(label: "2")
|
||||
handler2.metadata["two"] = "222"
|
||||
handler2.metadata["in"] = "in-2"
|
||||
handler2.metadataProvider = .constant([
|
||||
"provider-2": "provided-222",
|
||||
"provider-overlap": "provided-222",
|
||||
])
|
||||
let handler1 = {
|
||||
var handler1 = logging1.make(label: "1")
|
||||
handler1.metadataProvider = .constant([
|
||||
"provider-1": "provided-111",
|
||||
"provider-overlap": "provided-111",
|
||||
])
|
||||
return handler1
|
||||
}()
|
||||
let handler2 = {
|
||||
var handler2 = logging2.make(label: "2")
|
||||
handler2.metadata["two"] = "222"
|
||||
handler2.metadata["in"] = "in-2"
|
||||
handler2.metadataProvider = .constant([
|
||||
"provider-2": "provided-222",
|
||||
"provider-overlap": "provided-222",
|
||||
])
|
||||
return handler2
|
||||
}()
|
||||
|
||||
LoggingSystem.bootstrapInternal({ _, metadataProvider in
|
||||
MultiplexLogHandler(
|
||||
@@ -307,7 +327,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testDictionaryMetadata() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger[metadataKey: "foo"] = ["bar": "buz"]
|
||||
@@ -323,7 +343,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testListMetadata() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger[metadataKey: "foo"] = ["bar", "buz"]
|
||||
@@ -366,7 +386,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testStringConvertibleMetadata() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
var logger = Logger(label: "\(#function)")
|
||||
|
||||
logger[metadataKey: "foo"] = .stringConvertible("raw-string")
|
||||
@@ -386,7 +406,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testAutoClosuresAreNotForcedUnlessNeeded() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .error
|
||||
@@ -400,7 +420,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLocalMetadata() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.info("hello world!", metadata: ["foo": "bar"])
|
||||
@@ -441,7 +461,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testAllLogLevelsExceptCriticalCanBeBlocked() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .critical
|
||||
@@ -465,7 +485,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testAllLogLevelsWork() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .trace
|
||||
@@ -489,7 +509,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testAllLogLevelByFunctionRefWithSource() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .trace
|
||||
@@ -521,7 +541,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testAllLogLevelByFunctionRefWithoutSource() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .trace
|
||||
@@ -534,7 +554,6 @@ class LoggingTest: XCTestCase {
|
||||
let error = logger.error(_:metadata:file:function:line:)
|
||||
let critical = logger.critical(_:metadata:file:function:line:)
|
||||
|
||||
#if compiler(>=5.3)
|
||||
trace("yes: trace", [:], #fileID, #function, #line)
|
||||
debug("yes: debug", [:], #fileID, #function, #line)
|
||||
info("yes: info", [:], #fileID, #function, #line)
|
||||
@@ -542,15 +561,6 @@ class LoggingTest: XCTestCase {
|
||||
warning("yes: warning", [:], #fileID, #function, #line)
|
||||
error("yes: error", [:], #fileID, #function, #line)
|
||||
critical("yes: critical", [:], #fileID, #function, #line)
|
||||
#else
|
||||
trace("yes: trace", [:], #file, #function, #line)
|
||||
debug("yes: debug", [:], #file, #function, #line)
|
||||
info("yes: info", [:], #file, #function, #line)
|
||||
notice("yes: notice", [:], #file, #function, #line)
|
||||
warning("yes: warning", [:], #file, #function, #line)
|
||||
error("yes: error", [:], #file, #function, #line)
|
||||
critical("yes: critical", [:], #file, #function, #line)
|
||||
#endif
|
||||
|
||||
testLogging.history.assertExist(level: .trace, message: "yes: trace")
|
||||
testLogging.history.assertExist(level: .debug, message: "yes: debug")
|
||||
@@ -563,18 +573,14 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .trace
|
||||
|
||||
emitLogMessage("hello", to: logger)
|
||||
|
||||
#if compiler(>=5.3)
|
||||
let moduleName = "LoggingTests" // the actual name
|
||||
#else
|
||||
let moduleName = "SubDirectoryOfLoggingTests" // the last path component of `#file` showing the failure mode
|
||||
#endif
|
||||
|
||||
testLogging.history.assertExist(level: .trace, message: "hello", source: moduleName)
|
||||
testLogging.history.assertExist(level: .debug, message: "hello", source: moduleName)
|
||||
@@ -587,7 +593,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLogMessageWithStringInterpolation() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .debug
|
||||
@@ -600,7 +606,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLoggingAString() {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .debug
|
||||
@@ -633,9 +639,8 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLoggerWithoutFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider() {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal({ label, metadataProvider in
|
||||
logging.makeWithMetadataProvider(label: label, metadataProvider: metadataProvider)
|
||||
}, metadataProvider: .init { ["provider": "42"] })
|
||||
LoggingSystem.bootstrapInternal({ logging.makeWithMetadataProvider(label: $0, metadataProvider: $1) },
|
||||
metadataProvider: .init { ["provider": "42"] })
|
||||
|
||||
let logger = Logger(label: #function)
|
||||
|
||||
@@ -649,7 +654,7 @@ class LoggingTest: XCTestCase {
|
||||
func testLoggerWithPredefinedLibraryMetadataProvider() {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(
|
||||
logging.makeWithMetadataProvider,
|
||||
{ logging.makeWithMetadataProvider(label: $0, metadataProvider: $1) },
|
||||
metadataProvider: .exampleMetadataProvider
|
||||
)
|
||||
|
||||
@@ -664,7 +669,8 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
func testLoggerWithFactoryOverrideDefaultsToUsingLoggingSystemMetadataProvider() {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.makeWithMetadataProvider, metadataProvider: .init { ["provider": "42"] })
|
||||
LoggingSystem.bootstrapInternal({ logging.makeWithMetadataProvider(label: $0, metadataProvider: $1) },
|
||||
metadataProvider: .init { ["provider": "42"] })
|
||||
|
||||
let logger = Logger(label: #function, factory: { label in
|
||||
logging.makeWithMetadataProvider(label: label, metadataProvider: LoggingSystem.metadataProvider)
|
||||
@@ -700,11 +706,37 @@ class LoggingTest: XCTestCase {
|
||||
logger1.error("hey")
|
||||
}
|
||||
|
||||
/// Protects an object such that it can only be accessed while holding a lock.
|
||||
private final class LockedValueBox<Value: Sendable>: @unchecked Sendable {
|
||||
private let lock = Lock()
|
||||
private var storage: Value
|
||||
|
||||
init(initialValue: Value) {
|
||||
self.storage = initialValue
|
||||
}
|
||||
|
||||
func withLock<Result>(_ operation: (Value) -> Result) -> Result {
|
||||
self.lock.withLock {
|
||||
operation(self.storage)
|
||||
}
|
||||
}
|
||||
|
||||
func withLockMutating(_ operation: (inout Value) -> Void) {
|
||||
self.lock.withLockVoid {
|
||||
operation(&self.storage)
|
||||
}
|
||||
}
|
||||
|
||||
var underlying: Value {
|
||||
get { self.withLock { $0 } }
|
||||
set { self.withLockMutating { $0 = newValue } }
|
||||
}
|
||||
}
|
||||
|
||||
func testLoggerWithGlobalOverride() {
|
||||
struct LogHandlerWithGlobalLogLevelOverride: LogHandler {
|
||||
// the static properties hold the globally overridden log level (if overridden)
|
||||
private static let overrideLock = Lock()
|
||||
private static var overrideLogLevel: Logger.Level?
|
||||
private static let overrideLogLevel = LockedValueBox<Logger.Level?>(initialValue: nil)
|
||||
|
||||
private let recorder: Recorder
|
||||
// this holds the log level if not overridden
|
||||
@@ -720,9 +752,7 @@ class LoggingTest: XCTestCase {
|
||||
var logLevel: Logger.Level {
|
||||
// when we get asked for the log level, we check if it was globally overridden or not
|
||||
get {
|
||||
return LogHandlerWithGlobalLogLevelOverride.overrideLock.withLock {
|
||||
LogHandlerWithGlobalLogLevelOverride.overrideLogLevel
|
||||
} ?? self._logLevel
|
||||
return LogHandlerWithGlobalLogLevelOverride.overrideLogLevel.underlying ?? self._logLevel
|
||||
}
|
||||
// we set the log level whenever we're asked (note: this might not have an effect if globally
|
||||
// overridden)
|
||||
@@ -747,9 +777,7 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
// this is the function to globally override the log level, it is not part of the `LogHandler` protocol
|
||||
static func overrideGlobalLogLevel(_ logLevel: Logger.Level) {
|
||||
LogHandlerWithGlobalLogLevelOverride.overrideLock.withLock {
|
||||
LogHandlerWithGlobalLogLevelOverride.overrideLogLevel = logLevel
|
||||
}
|
||||
LogHandlerWithGlobalLogLevelOverride.overrideLogLevel.underlying = logLevel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,7 +1049,7 @@ class LoggingTest: XCTestCase {
|
||||
}
|
||||
// bootstrap with our test logging impl
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
var logger = Logger(label: "test")
|
||||
logger.logLevel = .error
|
||||
@@ -1038,8 +1066,8 @@ class LoggingTest: XCTestCase {
|
||||
}
|
||||
|
||||
// default usage
|
||||
LoggingSystem.bootstrap(StreamLogHandler.standardOutput)
|
||||
LoggingSystem.bootstrap(StreamLogHandler.standardError)
|
||||
LoggingSystem.bootstrap { (label: String) in StreamLogHandler.standardOutput(label: label) }
|
||||
LoggingSystem.bootstrap { (label: String) in StreamLogHandler.standardError(label: label) }
|
||||
|
||||
// with metadata handler, explicitly, public api
|
||||
LoggingSystem.bootstrap({ label, metadataProvider in
|
||||
@@ -1050,26 +1078,33 @@ class LoggingTest: XCTestCase {
|
||||
}, metadataProvider: .exampleMetadataProvider)
|
||||
|
||||
// with metadata handler, still pretty
|
||||
LoggingSystem.bootstrap(StreamLogHandler.standardOutput, metadataProvider: .exampleMetadataProvider)
|
||||
LoggingSystem.bootstrap(StreamLogHandler.standardError, metadataProvider: .exampleMetadataProvider)
|
||||
LoggingSystem.bootstrap({ (label: String, metadataProvider: Logger.MetadataProvider?) in StreamLogHandler.standardOutput(label: label, metadataProvider: metadataProvider) },
|
||||
metadataProvider: .exampleMetadataProvider)
|
||||
LoggingSystem.bootstrap({ (label: String, metadataProvider: Logger.MetadataProvider?) in StreamLogHandler.standardError(label: label, metadataProvider: metadataProvider) },
|
||||
metadataProvider: .exampleMetadataProvider)
|
||||
}
|
||||
|
||||
func testLoggerIsJustHoldingASinglePointer() {
|
||||
let expectedSize = MemoryLayout<UnsafeRawPointer>.size
|
||||
XCTAssertEqual(MemoryLayout<Logger>.size, expectedSize)
|
||||
}
|
||||
|
||||
func testLoggerCopyOnWrite() {
|
||||
var logger1 = Logger(label: "foo")
|
||||
logger1.logLevel = .error
|
||||
var logger2 = logger1
|
||||
logger2.logLevel = .trace
|
||||
XCTAssertEqual(.error, logger1.logLevel)
|
||||
XCTAssertEqual(.trace, logger2.logLevel)
|
||||
}
|
||||
}
|
||||
|
||||
extension Logger {
|
||||
#if compiler(>=5.3)
|
||||
public func error(error: Error,
|
||||
public func error(error: any Error,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#else
|
||||
public func error(error: Error,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extension Logger.MetadataProvider {
|
||||
@@ -1084,7 +1119,6 @@ extension Logger.MetadataProvider {
|
||||
|
||||
// Sendable
|
||||
|
||||
#if compiler(>=5.6)
|
||||
// used to test logging metadata which requires Sendable conformance
|
||||
// @unchecked Sendable since manages it own state
|
||||
extension LoggingTest.LazyMetadataBox: @unchecked Sendable {}
|
||||
@@ -1092,4 +1126,3 @@ extension LoggingTest.LazyMetadataBox: @unchecked Sendable {}
|
||||
// used to test logging stream which requires Sendable conformance
|
||||
// @unchecked Sendable since manages it own state
|
||||
extension LoggingTest.InterceptStream: @unchecked Sendable {}
|
||||
#endif
|
||||
@@ -1,31 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// MDCTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension MDCTest {
|
||||
static var allTests: [(String, (MDCTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("test1", test1),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class MDCTest: XCTestCase {
|
||||
func test1() throws {
|
||||
// bootstrap with our test logger
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
LoggingSystem.bootstrapInternal { logging.make(label: $0) }
|
||||
|
||||
// run the program
|
||||
MDC.global["foo"] = "bar"
|
||||
|
||||
@@ -1,33 +0,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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// MetadataProviderTest+XCTest.swift
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
|
||||
extension MetadataProviderTest {
|
||||
static var allTests: [(String, (MetadataProviderTest) -> () throws -> Void)] {
|
||||
return [
|
||||
("testLoggingMergesOneOffMetadataWithProvidedMetadataFromExplicitlyPassed", testLoggingMergesOneOffMetadataWithProvidedMetadataFromExplicitlyPassed),
|
||||
("testLogHandlerThatDidNotImplementProvidersButSomeoneAttemptsToSetOneOnIt", testLogHandlerThatDidNotImplementProvidersButSomeoneAttemptsToSetOneOnIt),
|
||||
("testLogHandlerThatDidImplementProvidersButSomeoneAttemptsToSetOneOnIt", testLogHandlerThatDidImplementProvidersButSomeoneAttemptsToSetOneOnIt),
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import Glibc
|
||||
final class MetadataProviderTest: XCTestCase {
|
||||
func testLoggingMergesOneOffMetadataWithProvidedMetadataFromExplicitlyPassed() throws {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.makeWithMetadataProvider,
|
||||
LoggingSystem.bootstrapInternal({ logging.makeWithMetadataProvider(label: $0, metadataProvider: $1) },
|
||||
metadataProvider: .init { ["common": "initial"]
|
||||
})
|
||||
|
||||
|
||||
@@ -17,12 +17,17 @@ import XCTest
|
||||
#if os(Windows)
|
||||
import WinSDK
|
||||
#endif
|
||||
#if compiler(>=6.0) || canImport(Darwin)
|
||||
import Dispatch
|
||||
#else
|
||||
@preconcurrency import Dispatch
|
||||
#endif
|
||||
|
||||
internal struct TestLogging {
|
||||
private let _config = Config() // shared among loggers
|
||||
private let recorder = Recorder() // shared among loggers
|
||||
|
||||
func make(label: String) -> LogHandler {
|
||||
func make(label: String) -> some LogHandler {
|
||||
return TestLogHandler(
|
||||
label: label,
|
||||
config: self.config,
|
||||
@@ -31,7 +36,7 @@ internal struct TestLogging {
|
||||
)
|
||||
}
|
||||
|
||||
func makeWithMetadataProvider(label: String, metadataProvider: Logger.MetadataProvider?) -> LogHandler {
|
||||
func makeWithMetadataProvider(label: String, metadataProvider: Logger.MetadataProvider?) -> (some LogHandler) {
|
||||
return TestLogHandler(
|
||||
label: label,
|
||||
config: self.config,
|
||||
@@ -41,7 +46,7 @@ internal struct TestLogging {
|
||||
}
|
||||
|
||||
var config: Config { return self._config }
|
||||
var history: History { return self.recorder }
|
||||
var history: some History { return self.recorder }
|
||||
}
|
||||
|
||||
internal struct TestLogHandler: LogHandler {
|
||||
@@ -210,7 +215,6 @@ internal struct LogEntry {
|
||||
}
|
||||
|
||||
extension History {
|
||||
#if compiler(>=5.3)
|
||||
func assertExist(level: Logger.Level,
|
||||
message: String,
|
||||
metadata: Logger.Metadata? = nil,
|
||||
@@ -237,32 +241,6 @@ extension History {
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
#else
|
||||
func assertExist(level: Logger.Level,
|
||||
message: String,
|
||||
metadata: Logger.Metadata? = nil,
|
||||
source: String? = nil,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line) {
|
||||
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
||||
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||
XCTAssertNotNil(entry, "entry not found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
func assertNotExist(level: Logger.Level,
|
||||
message: String,
|
||||
metadata: Logger.Metadata? = nil,
|
||||
source: String? = nil,
|
||||
file: StaticString = #file,
|
||||
line: UInt = #line) {
|
||||
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
||||
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||
XCTAssertNil(entry, "entry was found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||
file: file, line: line)
|
||||
}
|
||||
#endif
|
||||
|
||||
func find(level: Logger.Level, message: String, metadata: Logger.Metadata? = nil, source: String) -> LogEntry? {
|
||||
return self.entries.first { entry in
|
||||
if entry.level != level {
|
||||
@@ -303,7 +281,7 @@ public class MDC {
|
||||
private let lock = NSLock()
|
||||
private var storage = [Int: Logger.Metadata]()
|
||||
|
||||
public static var global = MDC()
|
||||
public static let global = MDC()
|
||||
|
||||
private init() {}
|
||||
|
||||
@@ -379,7 +357,7 @@ internal extension NSLock {
|
||||
}
|
||||
}
|
||||
|
||||
internal struct TestLibrary {
|
||||
internal struct TestLibrary: Sendable {
|
||||
private let logger = Logger(label: "TestLibrary")
|
||||
private let queue = DispatchQueue(label: "TestLibrary")
|
||||
|
||||
@@ -389,7 +367,7 @@ internal struct TestLibrary {
|
||||
self.logger.info("TestLibrary::doSomething")
|
||||
}
|
||||
|
||||
public func doSomethingAsync(completion: @escaping () -> Void) {
|
||||
public 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
|
||||
@@ -404,9 +382,7 @@ internal struct TestLibrary {
|
||||
|
||||
// Sendable
|
||||
|
||||
#if compiler(>=5.6)
|
||||
extension TestLogHandler: @unchecked Sendable {}
|
||||
extension Recorder: @unchecked Sendable {}
|
||||
extension Config: @unchecked Sendable {}
|
||||
extension MDC: @unchecked Sendable {}
|
||||
#endif
|
||||
@@ -11,15 +11,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
import Dispatch
|
||||
@testable import Logging
|
||||
import XCTest
|
||||
|
||||
class SendableTest: XCTestCase {
|
||||
#if compiler(>=5.6)
|
||||
func testSendableLogger() async {
|
||||
let testLogging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }
|
||||
|
||||
let logger = Logger(label: "test")
|
||||
let message1 = Logger.Message(stringLiteral: "critical 1")
|
||||
@@ -39,5 +37,4 @@ class SendableTest: XCTestCase {
|
||||
testLogging.history.assertExist(level: .critical, message: "critical 2", metadata: [:])
|
||||
testLogging.history.assertExist(level: .warning, message: "warning", metadata: metadata)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:18.04-5.0
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "bionic"
|
||||
swift_version: "5.0"
|
||||
|
||||
test:
|
||||
image: swift-log:18.04-5.0
|
||||
|
||||
shell:
|
||||
image: swift-log:18.04-5.0
|
||||
@@ -1,18 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:18.04-5.1
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "bionic"
|
||||
swift_version: "5.1"
|
||||
|
||||
test:
|
||||
image: swift-log:18.04-5.1
|
||||
environment: []
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:18.04-5.1
|
||||
@@ -1,18 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:18.04-5.2
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "bionic"
|
||||
swift_version: "5.2"
|
||||
|
||||
test:
|
||||
image: swift-log:18.04-5.2
|
||||
environment: []
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:18.04-5.2
|
||||
@@ -1,18 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:18.04-5.3
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "bionic"
|
||||
swift_version: "5.3"
|
||||
|
||||
test:
|
||||
image: swift-log:18.04-5.3
|
||||
environment: []
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:18.04-5.3
|
||||
@@ -1,18 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:20.04-5.4
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "focal"
|
||||
swift_version: "5.4"
|
||||
|
||||
test:
|
||||
image: swift-log:20.04-5.4
|
||||
environment: []
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:20.04-5.4
|
||||
@@ -1,19 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:20.04-5.5
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "focal"
|
||||
swift_version: "5.5"
|
||||
|
||||
test:
|
||||
image: swift-log:20.04-5.5
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:20.04-5.5
|
||||
@@ -1,19 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:20.04-5.6
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "focal"
|
||||
swift_version: "5.6"
|
||||
|
||||
test:
|
||||
image: swift-log:20.04-5.6
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:20.04-5.6
|
||||
@@ -1,19 +0,0 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-log:20.04-5.7
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "focal"
|
||||
swift_version: "5.7"
|
||||
|
||||
test:
|
||||
image: swift-log:20.04-5.7
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
image: swift-log:20.04-5.7
|
||||
@@ -12,7 +12,7 @@ services:
|
||||
test:
|
||||
image: swift-log:20.04-5.8
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
|
||||
@@ -11,8 +11,10 @@ services:
|
||||
test:
|
||||
image: swift-log:22.04-5.10
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
# Generated test manifest uses existentials without 'any'.
|
||||
#- EXISTENTIAL_ANY_ARG=-Xswiftc -enable-upcoming-feature -Xswiftc ExistentialAny
|
||||
|
||||
shell:
|
||||
image: swift-log:22.04-5.10
|
||||
@@ -12,7 +12,8 @@ services:
|
||||
test:
|
||||
image: swift-log:22.04-5.9
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
|
||||
- EXISTENTIAL_ANY_ARG=-Xswiftc -enable-upcoming-feature -Xswiftc ExistentialAny
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
shell:
|
||||
|
||||
@@ -11,8 +11,13 @@ services:
|
||||
test:
|
||||
image: swift-log:22.04-main
|
||||
environment:
|
||||
- FORCE_TEST_DISCOVERY=--enable-test-discovery
|
||||
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
|
||||
- EXPLICIT_SENDABLE_ARG=-Xswiftc -require-explicit-sendable
|
||||
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
|
||||
# Generated test manifest uses existentials without 'any'.
|
||||
#- EXISTENTIAL_ANY_ARG=-Xswiftc -enable-upcoming-feature -Xswiftc ExistentialAny
|
||||
|
||||
shell:
|
||||
image: swift-log:22.04-main
|
||||
@@ -28,7 +28,7 @@ services:
|
||||
|
||||
test:
|
||||
<<: *common
|
||||
command: /bin/bash -xcl "swift test -Xswiftc -warnings-as-errors $${FORCE_TEST_DISCOVERY-} $${SANITIZER_ARG-}"
|
||||
command: /bin/bash -xcl "swift test $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} $${EXPLICIT_SENDABLE_ARG-} $${STRICT_CONCURRENCY_ARG-} $${EXISTENTIAL_ANY_ARG-}"
|
||||
|
||||
# util
|
||||
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/bin/bash
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the Swift Logging API open source project
|
||||
##
|
||||
## Copyright (c) 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
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftNIO open source project
|
||||
##
|
||||
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
set -eu
|
||||
|
||||
function usage() {
|
||||
echo "$0 [-u] version"
|
||||
echo
|
||||
echo "OPTIONS:"
|
||||
echo " -u: Additionally upload the podspec"
|
||||
}
|
||||
|
||||
upload=false
|
||||
while getopts ":u" opt; do
|
||||
case $opt in
|
||||
u)
|
||||
upload=true
|
||||
;;
|
||||
\?)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$((OPTIND-1))"
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Must provide target version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version=$1
|
||||
podspec_name="Logging"
|
||||
|
||||
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
tmpdir=$(mktemp -d /tmp/.build_podspecsXXXXXX)
|
||||
echo "Building podspec in $tmpdir"
|
||||
|
||||
cat > "${tmpdir}/${podspec_name}.podspec" <<- EOF
|
||||
Pod::Spec.new do |s|
|
||||
s.name = '$podspec_name'
|
||||
s.version = '$version'
|
||||
s.license = { :type => 'Apache 2.0', :file => 'LICENSE.txt' }
|
||||
s.summary = 'A Logging API for Swift.'
|
||||
s.homepage = 'https://github.com/apple/swift-log'
|
||||
s.author = 'Apple Inc.'
|
||||
s.source = { :git => 'https://github.com/apple/swift-log.git', :tag => s.version.to_s }
|
||||
s.documentation_url = 'https://apple.github.io/swift-log'
|
||||
s.module_name = 'Logging'
|
||||
|
||||
s.swift_version = '5.0'
|
||||
s.cocoapods_version = '>=1.6.0'
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.osx.deployment_target = '10.9'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.watchos.deployment_target = '2.0'
|
||||
|
||||
s.source_files = 'Sources/Logging/**/*.swift'
|
||||
end
|
||||
EOF
|
||||
|
||||
if $upload; then
|
||||
echo "Uploading ${tmpdir}/${podspec_name}.podspec"
|
||||
pod trunk push "${tmpdir}/${podspec_name}.podspec"
|
||||
else
|
||||
echo "Linting ${tmpdir}/${podspec_name}.podspec"
|
||||
pod spec lint "${tmpdir}/${podspec_name}.podspec"
|
||||
fi
|
||||
@@ -17,7 +17,7 @@
|
||||
##
|
||||
## This source file is part of the SwiftNIO open source project
|
||||
##
|
||||
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
||||
## Copyright (c) 2017-2020 Apple Inc. and the SwiftNIO project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
@@ -29,44 +29,15 @@
|
||||
|
||||
set -eu
|
||||
|
||||
# repodir
|
||||
function all_modules() {
|
||||
local repodir="$1"
|
||||
(
|
||||
set -eu
|
||||
cd "$repodir"
|
||||
swift package dump-package | jq '.products |
|
||||
map(select(.type | has("library") )) |
|
||||
map(.name) | .[]' | tr -d '"'
|
||||
)
|
||||
}
|
||||
|
||||
# repodir tag output
|
||||
function build_and_do() {
|
||||
local repodir=$1
|
||||
local tag=$2
|
||||
local output=$3
|
||||
|
||||
(
|
||||
cd "$repodir"
|
||||
git checkout -q "$tag"
|
||||
swift build
|
||||
while read -r module; do
|
||||
swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \
|
||||
-o "$output/$module.json" -I "$repodir/.build/debug"
|
||||
done < <(all_modules "$repodir")
|
||||
)
|
||||
}
|
||||
|
||||
function usage() {
|
||||
echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..."
|
||||
echo >&2
|
||||
echo >&2 "This script requires a Swift 5.1+ toolchain."
|
||||
echo >&2 "This script requires a Swift 5.2+ toolchain."
|
||||
echo >&2
|
||||
echo >&2 "Examples:"
|
||||
echo >&2
|
||||
echo >&2 "Check between master and tag 2.1.1 of swift-nio:"
|
||||
echo >&2 " $0 https://github.com/apple/swift-nio master 2.1.1"
|
||||
echo >&2 "Check between main and tag 2.1.1 of swift-nio:"
|
||||
echo >&2 " $0 https://github.com/apple/swift-nio main 2.1.1"
|
||||
echo >&2
|
||||
echo >&2 "Check between HEAD and commit 64cf63d7 using the provided toolchain:"
|
||||
echo >&2 " xcrun --toolchain org.swift.5120190702a $0 ../some-local-repo HEAD 64cf63d7"
|
||||
@@ -77,12 +48,6 @@ if [[ $# -lt 3 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sdk=/
|
||||
if [[ "$(uname -s)" == Darwin ]]; then
|
||||
sdk=$(xcrun --show-sdk-path)
|
||||
fi
|
||||
|
||||
hash jq 2> /dev/null || { echo >&2 "ERROR: jq must be installed"; exit 1; }
|
||||
tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX)
|
||||
repo_url=$1
|
||||
new_tag=$2
|
||||
@@ -91,46 +56,13 @@ shift 2
|
||||
repodir="$tmpdir/repo"
|
||||
git clone "$repo_url" "$repodir"
|
||||
git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*'
|
||||
errors=0
|
||||
cd "$repodir"
|
||||
git checkout -q "$new_tag"
|
||||
|
||||
for old_tag in "$@"; do
|
||||
mkdir "$tmpdir/api-old"
|
||||
mkdir "$tmpdir/api-new"
|
||||
|
||||
echo "Checking public API breakages from $old_tag to $new_tag"
|
||||
|
||||
build_and_do "$repodir" "$new_tag" "$tmpdir/api-new/"
|
||||
build_and_do "$repodir" "$old_tag" "$tmpdir/api-old/"
|
||||
|
||||
for f in "$tmpdir/api-new"/*; do
|
||||
f=$(basename "$f")
|
||||
report="$tmpdir/$f.report"
|
||||
if [[ ! -f "$tmpdir/api-old/$f" ]]; then
|
||||
echo "NOTICE: NEW MODULE $f"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo -n "Checking $f... "
|
||||
swift api-digester -sdk "$sdk" -diagnose-sdk \
|
||||
--input-paths "$tmpdir/api-old/$f" -input-paths "$tmpdir/api-new/$f" 2>&1 \
|
||||
> "$report" 2>&1
|
||||
|
||||
if ! shasum "$report" | grep -q cefc4ee5bb7bcdb7cb5a7747efa178dab3c794d5; then
|
||||
echo ERROR
|
||||
echo >&2 "=============================="
|
||||
echo >&2 "ERROR: public API change in $f"
|
||||
echo >&2 "=============================="
|
||||
cat >&2 "$report"
|
||||
errors=$(( errors + 1 ))
|
||||
else
|
||||
echo OK
|
||||
fi
|
||||
done
|
||||
rm -rf "$tmpdir/api-new" "$tmpdir/api-old"
|
||||
swift package diagnose-api-breaking-changes "$old_tag"
|
||||
done
|
||||
|
||||
if [[ "$errors" == 0 ]]; then
|
||||
echo "OK, all seems good"
|
||||
fi
|
||||
echo done
|
||||
exit "$errors"
|
||||
@@ -1,231 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
#
|
||||
# process_test_files.rb
|
||||
#
|
||||
# Copyright 2016 Tony Stone
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Created by Tony Stone on 5/4/16.
|
||||
#
|
||||
require 'getoptlong'
|
||||
require 'fileutils'
|
||||
require 'pathname'
|
||||
|
||||
include FileUtils
|
||||
|
||||
#
|
||||
# This ruby script will auto generate LinuxMain.swift and the +XCTest.swift extension files for Swift Package Manager on Linux platforms.
|
||||
#
|
||||
# See https://github.com/apple/swift-corelibs-xctest/blob/master/Documentation/Linux.md
|
||||
#
|
||||
def header(fileName)
|
||||
string = <<-eos
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <FileName>
|
||||
//
|
||||
import XCTest
|
||||
|
||||
///
|
||||
/// NOTE: This file was generated by generate_linux_tests.rb
|
||||
///
|
||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||
///
|
||||
eos
|
||||
|
||||
string
|
||||
.sub('<FileName>', File.basename(fileName))
|
||||
.sub('<Date>', Time.now.to_s)
|
||||
end
|
||||
|
||||
def createExtensionFile(fileName, classes)
|
||||
extensionFile = fileName.sub! '.swift', '+XCTest.swift'
|
||||
print 'Creating file: ' + extensionFile + "\n"
|
||||
|
||||
File.open(extensionFile, 'w') do |file|
|
||||
file.write header(extensionFile)
|
||||
file.write "\n"
|
||||
|
||||
for classArray in classes
|
||||
file.write 'extension ' + classArray[0] + " {\n"
|
||||
file.write ' static var allTests: [(String, (' + classArray[0] + ") -> () throws -> Void)] {\n"
|
||||
file.write " return [\n"
|
||||
|
||||
for funcName in classArray[1]
|
||||
file.write ' ("' + funcName + '", ' + funcName + "),\n"
|
||||
end
|
||||
|
||||
file.write " ]\n"
|
||||
file.write " }\n"
|
||||
file.write "}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def createLinuxMain(testsDirectory, allTestSubDirectories, files)
|
||||
fileName = testsDirectory + '/LinuxMain.swift'
|
||||
print 'Creating file: ' + fileName + "\n"
|
||||
|
||||
File.open(fileName, 'w') do |file|
|
||||
file.write header(fileName)
|
||||
file.write "\n"
|
||||
|
||||
file.write "#if os(Linux) || os(FreeBSD) || os(Windows) || os(Android)\n"
|
||||
for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y }
|
||||
file.write '@testable import ' + testSubDirectory + "\n"
|
||||
end
|
||||
file.write "\n"
|
||||
file.write "XCTMain([\n"
|
||||
|
||||
testCases = []
|
||||
for classes in files
|
||||
for classArray in classes
|
||||
testCases << classArray[0]
|
||||
end
|
||||
end
|
||||
|
||||
for testCase in testCases.sort { |x, y| x <=> y }
|
||||
file.write ' testCase(' + testCase + ".allTests),\n"
|
||||
end
|
||||
file.write "])\n"
|
||||
file.write "#endif\n"
|
||||
end
|
||||
end
|
||||
|
||||
def parseSourceFile(fileName)
|
||||
puts 'Parsing file: ' + fileName + "\n"
|
||||
|
||||
classes = []
|
||||
currentClass = nil
|
||||
inIfLinux = false
|
||||
inElse = false
|
||||
ignore = false
|
||||
|
||||
#
|
||||
# Read the file line by line
|
||||
# and parse to find the class
|
||||
# names and func names
|
||||
#
|
||||
File.readlines(fileName).each do |line|
|
||||
if inIfLinux
|
||||
if /\#else/.match(line)
|
||||
inElse = true
|
||||
ignore = true
|
||||
else
|
||||
if /\#end/.match(line)
|
||||
inElse = false
|
||||
inIfLinux = false
|
||||
ignore = false
|
||||
end
|
||||
end
|
||||
else
|
||||
if /\#if[ \t]+os\(Linux\)/.match(line)
|
||||
inIfLinux = true
|
||||
ignore = false
|
||||
end
|
||||
end
|
||||
|
||||
next if ignore
|
||||
# Match class or func
|
||||
match = line[/class[ \t]+[a-zA-Z0-9_]*(?=[ \t]*:[ \t]*XCTestCase)|func[ \t]+test[a-zA-Z0-9_]*(?=[ \t]*\(\))/, 0]
|
||||
if match
|
||||
|
||||
if match[/class/, 0] == 'class'
|
||||
className = match.sub(/^class[ \t]+/, '')
|
||||
#
|
||||
# Create a new class / func structure
|
||||
# and add it to the classes array.
|
||||
#
|
||||
currentClass = [className, []]
|
||||
classes << currentClass
|
||||
else # Must be a func
|
||||
funcName = match.sub(/^func[ \t]+/, '')
|
||||
#
|
||||
# Add each func name the the class / func
|
||||
# structure created above.
|
||||
#
|
||||
currentClass[1] << funcName
|
||||
end
|
||||
end
|
||||
end
|
||||
classes
|
||||
end
|
||||
|
||||
#
|
||||
# Main routine
|
||||
#
|
||||
#
|
||||
|
||||
testsDirectory = 'Tests'
|
||||
|
||||
options = GetoptLong.new(['--tests-dir', GetoptLong::OPTIONAL_ARGUMENT])
|
||||
options.quiet = true
|
||||
|
||||
begin
|
||||
options.each do |option, value|
|
||||
case option
|
||||
when '--tests-dir'
|
||||
testsDirectory = value
|
||||
end
|
||||
end
|
||||
rescue GetoptLong::InvalidOption
|
||||
end
|
||||
|
||||
allTestSubDirectories = []
|
||||
allFiles = []
|
||||
|
||||
Dir[testsDirectory + '/*'].each do |subDirectory|
|
||||
next unless File.directory?(subDirectory)
|
||||
directoryHasClasses = false
|
||||
Dir[subDirectory + '/*Test{s,}.swift'].each do |fileName|
|
||||
next unless File.file? fileName
|
||||
fileClasses = parseSourceFile(fileName)
|
||||
|
||||
#
|
||||
# If there are classes in the
|
||||
# test source file, create an extension
|
||||
# file for it.
|
||||
#
|
||||
next unless fileClasses.count > 0
|
||||
createExtensionFile(fileName, fileClasses)
|
||||
directoryHasClasses = true
|
||||
allFiles << fileClasses
|
||||
end
|
||||
|
||||
if directoryHasClasses
|
||||
allTestSubDirectories << Pathname.new(subDirectory).split.last.to_s
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Last step is the create a LinuxMain.swift file that
|
||||
# references all the classes and funcs in the source files.
|
||||
#
|
||||
if allFiles.count > 0
|
||||
createLinuxMain(testsDirectory, allTestSubDirectories, allFiles)
|
||||
end
|
||||
# eof
|
||||
@@ -7,7 +7,7 @@
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of Swift Logging API project authors
|
||||
## See CONTRIBUTORS.txt for the list of Swift Logging API project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
|
||||
+1
-13
@@ -35,18 +35,6 @@ function replace_acceptable_years() {
|
||||
sed -e 's/20[12][789012]-20[12][89012]/YEARS/' -e 's/20[12][89012]/YEARS/'
|
||||
}
|
||||
|
||||
printf "=> Checking linux tests... "
|
||||
FIRST_OUT="$(git status --porcelain)"
|
||||
ruby "$here/../scripts/generate_linux_tests.rb" > /dev/null
|
||||
SECOND_OUT="$(git status --porcelain)"
|
||||
if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
|
||||
printf "\033[0;31mmissing changes!\033[0m\n"
|
||||
git --no-pager diff
|
||||
exit 1
|
||||
else
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
fi
|
||||
|
||||
printf "=> Checking for unacceptable language... "
|
||||
# This greps for unacceptable terminology. The square bracket[s] are so that
|
||||
# "git grep" doesn't find the lines that greps :).
|
||||
@@ -86,7 +74,7 @@ for language in swift-or-c bash dtrace; do
|
||||
matching_files=( -name '*' )
|
||||
case "$language" in
|
||||
swift-or-c)
|
||||
exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o name Package-swift5.6.swift -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h)
|
||||
exceptions=( -name c_nio_http_parser.c -o -name c_nio_http_parser.h -o -name cpp_magic.h -o -name Package.swift -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h)
|
||||
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
|
||||
cat > "$tmp" <<"EOF"
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in new issue
Block a user