Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Last active December 29, 2015 07:29
Show Gist options
  • Save sag333ar/7636866 to your computer and use it in GitHub Desktop.
Save sag333ar/7636866 to your computer and use it in GitHub Desktop.
NSLog without date time stamp, application name, and process id info.
#define NSLog(args...) CustomLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, args)
static inline void CustomLog(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]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment