Home Custom NSLog
Post
Cancel

Custom NSLog

ZKLog

Writing our own NSLog using c-function with variable length arguments.

I’ve used fprintf() function to write on console, because it sends the formatted output to the stream, where printf() internally invokes fprintf() with stdout.

stderr stands for standard error device. The benefit of doing this is that anything written to standard error is not buffered so it is immediately written to the screen and is useful for debugging.

void ZKLog(NSString*msg,…) {   va_list arguments;   va_start(arguments, msg);   NSString* message = [[NSString alloc] initWithFormat:msg arguments:arguments]; va_end(arguments); fprintf(stderr, “\n%s\n”, [message UTF8String]); [message release]; message = nil; }

This post is licensed under CC BY 4.0 by the author.