I'm using CocoaLumberJack to write to a logging file and I want to be able to attach the file/and or its contents to upload for analysis during execution if the app detects an unexpected situation while its running.
In which case I want to log to be up to date and contain all logging that might have been written just microseconds before.
i.e. given this code:
DDLogWarn(@"%@", @"Want this line to appear in the file");
if ([[NSFileManager defaultManager] fileExistsAtPath:logthLocation.path]) {
NSError* error = nil;
NSStringEncoding encoding = 0;
NSString *contents = [[NSString alloc] initWithContentsOfURL:logURL
usedEncoding:&encoding
error:&error];
Then the contents string won't contain the line just previously written.
The async/sync writing nature can be set at compile time via setting #define LOG_ASYNC_ENABLED to YES or NO
However for efficiency I want logging to be asynchronous by default, but to be able to flush any pending writes before opening the file. Is that possible?
[DDLog flushLog] seems to do the job