Last active
December 22, 2015 03:49
-
-
Save hashier/6413042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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, ...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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