Digital Media Mac Blogs > Mac

GSLog: Another way to log


A short while back, I wrote about my difficulties in redirecting log phone data. At the time, I could not get NSLog to properly redirect to a file using stderr. I was frustrated by the fact that NSLog didn't seem to output properly.

This past weekend, I made a startling discovery. Apple included another log function, hidden in its GraphicsServices framework. It's called GSLog and as far as I can tell, acts almost exactly like NSLog except it works correctly and will redirect its output via a freopen call on stderr.

So why did Apple introduce yet another log function? Wasn't NSLog enough? It all falls into the mysteries of the GraphicsServices framework, a framework that's absolutely full of hidden gems like this one.

To use GSLog, just invoke it exactly the way you would invoke NSLog. Make sure you compile linking to the GraphicsServices framework and bob's your uncle. Ignore any warnings that might crop up.

#import <UIKit/UIKit.h>
#import <UIKit/UIApplication.h>
#include <stdarg.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    freopen("/tmp/outlog", "a", stderr);
    GSLog(@"testing");
}

Categories





AddThis Social Bookmark Button



Comments (1)
Read More Entries by Erica Sadun.

1 Comments

You are a lifesaver, Erica.

Leave a comment


Type the characters you see in the picture above.

Topics of Interest

Related Books

Archives


 
 


Or, visit our complete archive.  

Stay Connected