Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I would like to read console Log From iOS 10

Tags:

ios10

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(&timestamp);
    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?

like image 863
khaled Avatar asked Sep 07 '16 06:09

khaled


1 Answers

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."

like image 85
Rob Wright Avatar answered Sep 23 '22 01:09

Rob Wright