From 78b84e39ffcdaa2dc4be83ba8f674d599d94e2ce Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Tue, 5 Mar 2019 19:44:46 +0000 Subject: [PATCH] address #2: provide an example logging a String (#3) - fixes #2 --- Tests/LoggingTests/LoggingTest.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/LoggingTests/LoggingTest.swift b/Tests/LoggingTests/LoggingTest.swift index 0b355fe..cfa5ab7 100644 --- a/Tests/LoggingTests/LoggingTest.swift +++ b/Tests/LoggingTests/LoggingTest.swift @@ -270,4 +270,20 @@ class LoggingTest: XCTestCase { testLogging.history.assertExist(level: .debug, message: "My favourite number is \(someInt) and not \(someInt - 1)" as String) } + + func testLoggingAString() { + let testLogging = TestLogging() + LoggingSystem.bootstrapInternal(testLogging.make) + + var logger = Logger(label: "\(#function)") + logger.logLevel = .debug + + let anActualString: String = "hello world!" + // We can't stick an actual String in here because we expect a Logger.Message. If we want to log an existing + // `String`, we can use string interpolation. The error you'll get trying to use the String directly is: + // + // error: Cannot convert value of type 'String' to expected argument type 'Logger.Message' + logger.debug("\(anActualString)") + testLogging.history.assertExist(level: .debug, message: "hello world!") + } }