我使用asl日志记录框架来记录各种错误级别,然后使用方法显示它们。我遇到的错误很奇怪,我用来显示所有级别日志的方法适用于iOS 5,但在iOS 6中,它只返回有警告级别的日志。
-(NSArray*) retrieveLogsWithLevel:(LoggingLevels)level_in forQueryOperation:(QueryOperations)queryOperation
{
[self.accessLock lock];
// subscribe for low memory notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(lowMemoryNotificationReceived:)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
// build the query
aslmsg aslQuery = asl_new(ASL_TYPE_QUERY);
const int setQueryStatus1 = asl_set_query(aslQuery, ASL_KEY_SENDER, [self usedByAppName], ASL_QUERY_OP_EQUAL);
if( (setQueryStatus1 != 0) /*|| (setQueryStatus2 != 0)*/ )
{
return [NSArray array];
}
// convert enum to string representation
char buff[2];
sprintf(buff, "%d", level_in);
asl_set_query(aslQuery, ASL_KEY_LEVEL, buff/*"4"*/,
queryOperation | ASL_QUERY_OP_NUMERIC);
// execute query
aslresponse response = asl_search(NULL, aslQuery);
asl_free( aslQuery );
NSArray* results = [self extractResults:response];
// free the response
aslresponse_free(response);
// unsubscribe from low memory notifications
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self.accessLock unlock];
return results;
}
我在模拟器上尝试了相同的代码并返回所有条目。只有在iOS6上运行的设备才会失败。