mirror of
https://github.com/apple/swift-log
synced 2026-11-26 04:07:49 +00:00
motivation: support situations when users want to multiplex to multiple logging implementations changes: * add MultiplexLogging (factory) and MUXLogHandler (implementation), allowing user to plug in multiple logging implementations * add tests and examples to demonstrate the functionality
22 lines
890 B
Swift
22 lines
890 B
Swift
@testable import Logging
|
|
import XCTest
|
|
|
|
class LoggingTest: XCTestCase {
|
|
func testMUX() throws {
|
|
// bootstrap with our test logging impl
|
|
let logging1 = TestLogging()
|
|
let logging2 = TestLogging()
|
|
Logging.bootstrap(MultiplexLogging([logging1.make, logging2.make]).make)
|
|
|
|
var logger = Logging.make("test")
|
|
logger.logLevel = .warn
|
|
logger.info("hello world")
|
|
logger[metadataKey: "foo"] = "bar"
|
|
logger.warn("hello world!")
|
|
logging1.history.assertNotExist(level: .info, metadata: nil, message: "hello world")
|
|
logging2.history.assertNotExist(level: .info, metadata: nil, message: "hello world")
|
|
logging1.history.assertExist(level: .warn, metadata: ["foo": "bar"], message: "hello world!")
|
|
logging2.history.assertExist(level: .warn, metadata: ["foo": "bar"], message: "hello world!")
|
|
}
|
|
}
|