Skip to content

Commit 0e21dd7

Browse files
authored
test that demonstrates overloading (#123)
Motivation: SwiftLog is meant as a base logging library so users will often overload certain functions with their own specialised and opinionated overloads. Modification: Add a test as demonstration. Result: More tests.
1 parent 4d7ef13 commit 0e21dd7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Tests/LoggingTests/LoggingTest+XCTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extension LoggingTest {
4545
("testStreamLogHandlerOutputFormat", testStreamLogHandlerOutputFormat),
4646
("testStreamLogHandlerOutputFormatWithMetaData", testStreamLogHandlerOutputFormatWithMetaData),
4747
("testStdioOutputStreamFlush", testStdioOutputStreamFlush),
48+
("testOverloadingError", testOverloadingError),
4849
]
4950
}
5051
}

Tests/LoggingTests/LoggingTest.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,29 @@ class LoggingTest: XCTestCase {
550550

551551
fds.forEach { close($0) }
552552
}
553+
554+
func testOverloadingError() {
555+
struct Dummy: Error, LocalizedError {
556+
var errorDescription: String? {
557+
return "errorDescription"
558+
}
559+
}
560+
// bootstrap with our test logging impl
561+
let logging = TestLogging()
562+
LoggingSystem.bootstrapInternal(logging.make)
563+
564+
var logger = Logger(label: "test")
565+
logger.logLevel = .error
566+
logger.error(Dummy())
567+
568+
logging.history.assertExist(level: .error, message: "errorDescription")
569+
}
570+
}
571+
572+
extension Logger {
573+
public func error(_ error: Error,
574+
metadata: @autoclosure () -> Logger.Metadata? = nil,
575+
file: String = #file, function: String = #function, line: UInt = #line) {
576+
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
577+
}
553578
}

0 commit comments

Comments
 (0)