Closed epatey closed 10 years ago
Good catch.
I'm a little worried about dispatch_syncing from this, since it's called from the main thread and the log queue might back up under heavy logging (many messages per second).
An alternative might be to dispatch all self.consoleMessages
operations onto the main queue. The downside may be clogging up the main thread under heavy logging, but it might be worth it for faster safe access to the messages under normal circumstances.
What do you think?
I'm not a fan of doing logging work on the main queue. Good point about blocking main thread if there's a lot of backed up logging.
Better still might be to just make currentConsoleLogWithDateStamps
async with a completion block and then just dispatch-async, but that may be more involved.
How about this? #19
Looks good. Thanks.
Thanks for the code!
-currentConsoleLogWithDateStamps:
accessesself.consoleMessages
from the wrong queue. Because of this, while enumerating the collection here:concurrent calls to
+addLogMessage:
mutate the collection causing an exception.This could mostly be fixed with
[self.consoleMessages copy]
. Technically, though, since it's never good to access an NS collection from multiple threads a better fix probably requires adispatch_sync(self.logQueue, ^{
. If it's cool to be on that queue for a while, just execute the whole loop on the queue.Alternatively, you could just copy the collection while dispatched to the proper queue:
I'll happily do a pull request with either approach based on feedback.