Swift debug logging is impaired by lack of macros
| Originator: | kamikaze.mark | ||
| Number: | rdar://17189125 | Date Originated: | 2014-06-05 |
| Status: | Closed | Resolved: | Duplicate 17257757 |
| Product: | OS X SDK | Product Version: | Xcode6-Beta |
| Classification: | Enhancement | Reproducible: | Always |
Swift debug logging is impaired by lack of macros
When debugging in Objective-C, I use:
#ifdef DEBUG
#define DLOG(fmt, ...) NSLog(@"%s: " fmt, __PRETTY_FUNCTION__, ##__VA_ARGS__)
#else
#define DLOG(...)
#endif
So DLOG(@"") prints a nice message to the log in Debug, nothing and consuming no time in Release.
The equivalent in Swift is writing at every debug point:
#if DEBUG
NSLog("\(__FUNCTION__):\(__LINE__): ")
#endif
The alternatives I can see are A) Reimplementing macros, possibly in a more sanitary way than CPP does, or B) Adding a logging function that only runs when DEBUG is defined, and includes the equivalent of __PRETTY_FUNCTION__.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!