Skip to content

Commit

Permalink
allow string interpolations in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi committed Mar 1, 2019
1 parent 306f432 commit 7dd7738
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ extension Logger.MetadataValue: Equatable {
}

extension Logger {
public struct Message: ExpressibleByStringLiteral, Equatable, CustomStringConvertible {
public struct Message: ExpressibleByStringLiteral, Equatable, CustomStringConvertible, ExpressibleByStringInterpolation {
public typealias StringLiteralType = String

private var value: String
Expand Down
13 changes: 13 additions & 0 deletions Tests/LoggingTests/LoggingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,17 @@ class LoggingTest: XCTestCase {
testLogging.history.assertExist(level: .alert, message: "yes")
testLogging.history.assertExist(level: .emergency, message: "yes")
}

func testLogMessageWithStringInterpolation() {
let testLogging = TestLogging()
LoggingSystem.bootstrapInternal(testLogging.make)

var logger = Logger(label: "\(#function)")
logger.logLevel = .debug

let someInt = Int.random(in: 23..<42)
logger.debug("My favourite number is \(someInt) and not \(someInt - 1)")
testLogging.history.assertExist(level: .debug,
message: "My favourite number is \(someInt) and not \(someInt - 1)" as String)
}
}

0 comments on commit 7dd7738

Please sign in to comment.