Replaced the "test" static constant for the Logger+Constants extension in the test target with a "test(level: handler: )" function for the Logger+Helpers extension.
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Hummingbird DocC Middleware open source project
|
||||
//
|
||||
// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import Logging
|
||||
import Testing
|
||||
|
||||
extension Logger {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// Creates a logger instance that is ready to use in test cases.
|
||||
static let test: Self = {
|
||||
var logger = Logger(label: "test.hummingbird-docc-middleware.logger")
|
||||
|
||||
logger.logLevel = try! #require(Logger.Level.allCases.randomElement())
|
||||
|
||||
logger[metadataKey: "hb.request.id"] = "\(UUID().uuidString)"
|
||||
|
||||
return logger
|
||||
}()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Hummingbird DocC Middleware open source project
|
||||
//
|
||||
// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors
|
||||
// Licensed under the EUPL 1.2 or later.
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import Testing
|
||||
|
||||
import protocol Logging.LogHandler
|
||||
|
||||
import struct Logging.Logger
|
||||
|
||||
extension Logger {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Generates a logger instance that is ready to use in test cases.
|
||||
/// - Parameters:
|
||||
/// - level: A logger level, if any.
|
||||
/// - handler: A custom log handler, if any.
|
||||
/// - Returns: A generated logger instance ready to use in test cases.
|
||||
static func test(
|
||||
level: Logger.Level? = nil,
|
||||
handler: (any LogHandler)? = nil
|
||||
) -> Self {
|
||||
var logger: Logger = if let handler {
|
||||
.init(label: .loggerLabel) { _ in handler }
|
||||
} else {
|
||||
.init(label: .loggerLabel)
|
||||
}
|
||||
|
||||
logger.logLevel = if let level {
|
||||
level
|
||||
} else {
|
||||
try! #require(Logger.Level.allCases.randomElement())
|
||||
}
|
||||
|
||||
logger[metadataKey: "hb.request.id"] = "\(UUID().uuidString)"
|
||||
|
||||
return logger
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private extension String {
|
||||
/// A label to assign to a test logger instance.
|
||||
static let loggerLabel = "test.hummingbird-docc-middleware.logger"
|
||||
}
|
||||
Reference in New Issue
Block a user