I was using this code but it is no longer working on iOS 10 because of changing all APIs related to Logging System.
+ (NSString *)getConsoleLog {
NSString *consoleLog = @"";
char fdate[24];
NSString *myPID = [NSString stringWithFormat:@"%d", getpid()];
aslmsg query, msg;
query = asl_new(ASL_TYPE_QUERY);
asl_set_query(query, ASL_KEY_PID, myPID.UTF8String, ASL_QUERY_OP_EQUAL);
aslresponse r = asl_search(NULL, query);
while ((msg = aslresponse_next(r))) {
NSString *secondsString = [NSString stringWithFormat:@"%s", asl_get(msg, ASL_KEY_TIME)];
NSString *nanoSecondsString = [NSString stringWithFormat:@"%s", asl_get(msg, ASL_KEY_TIME_NSEC)];
NSTimeInterval seconds = [secondsString doubleValue];
NSTimeInterval nanoSeconds = [nanoSecondsString doubleValue];
NSTimeInterval msgTime = seconds + nanoSeconds / NSEC_PER_SEC;
time_t timestamp = (time_t)msgTime;
struct tm *lt = localtime(×tamp);
strftime(fdate, 24, "%Y-%m-%d %T", lt);
consoleLog = [consoleLog stringByAppendingFormat:@"%s.%03d %@\n", fdate, (int)(1000.0 * (msgTime - floor(msgTime))), [NSString stringWithFormat:@"%s", asl_get(msg, ASL_KEY_MSG)]];
}
aslresponse_free(r);
asl_free(query);
return consoleLog; }
Can anyone help?
Beginning in iOS 10 NSLog
redirects to the new logging system and there is no search API.
From the WWDC 2016 Session 721 - Unified Logging and Activity Tracing
"...all of the legacy APIs, NSLog, asl log, message syslog, all of those will get redirected into the new system. ...but out-of-the-box if you just build with the new system it'll all get directed into the new logging architecture."
Time 41:47 "First off, all of the ASL logging APIs are now superseded by these new APIs and, therefore, those old APIs are deprecated. There is an interesting edge case though. A new API for searching the log data is not going to be made public in this release. What that means is that there's no equivalent to asl search functionality. If you absolutely depend on asl search in your system that may be a reason to wait for adopting the new logging system. There's also some APIs from activities that are being deprecated."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With