I would like to read the Log From iOS 10 console

I used this code, but it no longer works on iOS 10 due to a change in all the APIs associated with the 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?

+8
ios10
source share
1 answer

Starting with iOS 10, NSLog redirected to the new logging system and there is no search API.

From WWDC 2016 Session 721 - Unified Journal and Activity Tracking
"... all obsolete APIs, NSLog, asl log, syslog messages, all of them will be redirected to the new system ... but out of the box, if you just create a new system, everyone will be sent to the new logging architecture."

Time 41:47 "First, all ASL APIs are now replaced by these new APIs and therefore those old APIs are outdated. However, there is an interesting regional question: the new API for searching log data will not be published in this version. This means there is no equivalent to the asl search function. If you are completely dependent on asl, do a search on your system, which may cause you to wait for the adoption of a new logging system. There are also some APIs that are out of date. "

+1
source share

All Articles