Skip to content

Instantly share code, notes, and snippets.

@hashier
Last active December 22, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashier/6413042 to your computer and use it in GitHub Desktop.
Save hashier/6413042 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#ifdef DEBUG
#define NSLog(args...) ExtendNSLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args);
#else
#define NSLog(x...)
#endif
void ExtendNSLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...);
#import "ExtendNSLogFunctionality.h"
void ExtendNSLog(const char *file, int lineNumber, const char *functionName, NSString *format, ...) {
// Type to hold information about variable arguments.
va_list ap;
// Initialize a variable argument list.
va_start (ap, format);
// NSLog only adds a newline to the end of the NSLog format if
// one is not already there.
// Here we are utilizing this feature of NSLog()
if (![format hasSuffix: @"\n"]) {
format = [format stringByAppendingString: @"\n"];
}
NSString *body = [[NSString alloc] initWithFormat:format arguments:ap];
// End using variable argument list.
va_end (ap);
NSString *fileName = [[NSString stringWithUTF8String:file] lastPathComponent];
fprintf(stderr, "(%s) (%s:%d) %s", functionName, [fileName UTF8String], lineNumber, [body UTF8String]);
}
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ExtendNSLog.h"
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment