I am trying out XCGLogger and noticed that if I have a logging statement that includes an object instance from a class that implements both CustomDebugStringConvertible and CustomStringConvertible the logger doesn't call the debugDescription property but only seems to invoke the description property from CustomStringConvertible.
My implementation of debugDescription contains additional information over the description property that I would like to be used in logging.
In this situation when both protocols are implemented is their a way to have the logger use debugDescription over description by default?
If only either CustomStringConvertible or CustomDebugStringConvertible is implemented does the logger detect this and use the implemented protocol?
Thanks
Using
CustomStringConvertibleorCustomDebugStringConvertibleis something that happens before the string reachesXCGLogger. String interpolation will use thedescriptionproperty ofCustomStringConvertibleand not thedebugDescriptionproperty ofCustomDebugStringConvertible.debugDescriptionis only used when an object conforming toCustomDebugStringConvertibleis passed to thedebugPrint()method direction, not inside of quotes.For example:
A possible solution for you would be do add
-DDEBUGto yourOther Swift Flags(if not already there), and alter yourdescriptionproperty to be something like this:Then for debug builds, you'll get the
debugDescriptionvalue used in string interpolation, but in your production builds, you'll get your normaldescription.