我正在使用 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 的设备上才会失败。