1
我有這個梅索德:我怎麼能在日誌文件中搜索在IOS與ASL另一個PID
q = asl_new(ASL_TYPE_QUERY);
asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
// Count the number of results
r = asl_search(NULL, q);
while (NULL != (m = aslresponse_next(r))) {
counter++;
}
r = asl_search(NULL, q);
while (line++ < counter && NULL != (m = aslresponse_next(r)))
{
// Take only the latest results
if (!(line < counter-NUMBER_OF_LOG_MESSAGES)) {
log = [NSMutableDictionary dictionary];
for (i = 0; (NULL != (key = asl_key(m, i))); i++)
{
keyString = [NSString stringWithUTF8String:(char *)key];
if ([self.logKeyFilter containsObject:keyString]) {
val = asl_get(m, key);
string = [NSString stringWithUTF8String:val];
[log setObject:string forKey:keyString];
}
}
date = [dateFormat stringFromDate:[NSDate dateWithTimeIntervalSince1970:[[log objectForKey:@"Time"] doubleValue]]];
[logs addObject:[NSString stringWithFormat:@"%@ %@ %@", date, [self.logLevelKeyFilter objectForKey:[log objectForKey:@"Level"]], [log objectForKey:@"Message"]]];
}
}
aslresponse_free(r);
return logs;
其返回最新日誌「MyApp的」。 NUMBER_OF_LOG_MESSAGES這裏只是取最新的日誌。
問題是,當我有MyApp的崩潰與PID X和我重新啓動MyApp的漁獲日誌,我只有日誌我的新PID Y.
所以,我怎麼能在每一個日誌搜索文件來查找MyApp的日誌。
謝謝。