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,973
  • 1
  • 20
  • 43
  • Possibly helpful: https://stackoverflow.com/q/41680004/1187415, https://stackoverflow.com/q/36916772/1187415 – Martin R Feb 06 '20 at 11:55
  • Check this too: https://stackoverflow.com/questions/39026752/swift-extending-functionality-of-print-function – Keshu R. Feb 06 '20 at 12:00

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
}
Keshu R.
  • 5,045
  • 1
  • 18
  • 38