我有这个方法:
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 仅用于获取最新日志。
问题是当我使用 PID X 的 MyApp 崩溃并且我重新启动 MyApp 以捕获日志时,我只有新 PID Y 的日志。
那么,我如何在每个日志文件中搜索以找到 MyApp 的日志。
谢谢你。