0

Here i want track all NSLog(), Swift print() and other print-family functions.

Means i want to track all log print on debugging window in xcode and save to local storage.

I have tried with macro and this is my code but not worked for me.

#ifdef DEBUG
#define NSLog(args...) ExtendNSLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args)
#else
#define NSLog(x...)
#endif

void _Log(NSString *prefix, const char *file, int lineNumber, const char *funcName, NSString *format,...);

Now i want everytime NSLog() print anything it will call this method and than i store it into one file simple.

If you want more details please ask.

Thank you in advance.

Hardik Vyas
  • 1,605
  • 18
  • 39

1 Answers1

1

Add this to any .swift file in your project. This function will be called everytime print() is called in your project.

public func print(_ items: Any...) {
    #if DEBUG
        Swift.print(items)
        // append items to your file here
    #else
        Swift.print("Release")
    #endif
}
iOSArchitect.com
  • 4,710
  • 1
  • 14
  • 36