-
Hi there, I've some warnings in my project where I use the DDLogInfo macro, with an suggestion to use DDLogMessageFormat:
This warning occurs only in Swift code (I have both: Objective C and Swift code) and only at parameterized messages. Best thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Simply use a Swift string literal for logging messages: DDLogInfo("My log message") If you have parameters in your log message, use a Swift string interpolation: let parameter = "My Parameter"
DDLogInfo("My log message with parameter: \(parameter)") Old vs. new examplesIf you've previously had a string as the message in a separate variable, inline it into the Old: let message = "My message"
DDLogInfo(message) New: DDLogInfo("My message")
// OR (always evaluating the message)
let message: DDLogMessageFormat = "My message"
DDLogInfo(message) If you have previously passed an arbitrary value to the Old: let myValue = getSomeValue()
DDLogInfo(myValue) New: let myValue = getSomeValue()
DDLogInfo("\(myValue)") Wrapper examplesIf you're using a wrapper around the `DDLogXYZ` functions, make sure their message parameter is now of type `DDLogMessageFormat`. After that, the same rules apply for your wrapper as with `DDLogXYX` explained above.Old: func myInfoLogWrapper(_ message: Any) {
DDLogInfo(message)
} New: func myInfoLogWrapper(_ message: DDLogMessageFormat) {
DDLogInfo(message)
} |
Beta Was this translation helpful? Give feedback.
Simply use a Swift string literal for logging messages:
If you have parameters in your log message, use a Swift string interpolation:
Old vs. new examples
If you've previously had a string as the message in a separate variable, inline it into the
DDLogXYZ
call. Alternatively, declare it as aDDLogMessageFormat
. Note however, that the latter will always evaluate the message even if won't be logged due to the configured level.Old:
New: