Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> LOGGING FROM DIFFERENT BACKGROUND THREADS AT ONCE

Or, you could just make a logging serial queue that you send all log messages to; that way there's no risk of activity on the main thread slowing down your logging. In (Obj-)C:

    static queue_t queue;
    void log (NSString *message) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            queue = dispatch_queue_create("logging", DISPATCH_QUEUE_SERIAL);
        });
        dispatch_async(queue, ^{
            NSLog(message);
        });
    }


This only works right if none of the frameworks you use log anything by themselves - messages will get garbled otherwise. Logging through the main queue exhibits the same issue, but at least Cocoa logging (which is always in the main thread) is dealt with.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: