我使用CocoaLumberjack和DDASLLogger来获取ASL的日志条目,并且我希望在同一个日志中有一个包含misc :ed输出的3:rd的日志和我自己的日志。
为了得到更好的图片,我提取了对ASL的调用并做了一个例子。我遇到的问题是,这个ASL提取方法只查找用NSLog编写的条目,而不是用asl_log编写的条目。
下面是组织者控制台的一个示例:
Apr 17 20:34:48 Claes-Ls-iPhone-4s ASLLogTest[7253] <Warning>: NSLog 7
Apr 17 20:34:51 Claes-Ls-iPhone-4s ASLLogTest[7253] <Critical>: ASLLog 7当提取这个时,我只得到NSLog行。
下面是使用的代码:
写入ASL:
NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary;
NSString *productName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
_client = asl_open(productName.UTF8String, "com.apple.console", 0);
int status = asl_log(_client, NULL, ASL_LEVEL_CRIT, "%s", string.UTF8String);从ASL读取(不提供完整的迭代遍历-asl,但有效):
// Using ASL_QUERY_OP_TRUE to be dead-sure.
q = asl_new(ASL_TYPE_QUERY);
asl_set_query(q, ASL_KEY_SENDER, productName.UTF8String, ASL_QUERY_OP_TRUE);
aslresponse r = asl_search(NULL, q);我错过了什么,不可能写到ASL,然后用这种方式阅读吗?
谢谢,克拉斯
发布于 2015-05-12 18:17:36
如果您使用Swift,有一个名为CleanroomASL的新开源项目,它提供了一个类型安全的API,用于读取和写入Apple条目。
查询给定.Sender的日志(假设productName是String或NSString):
let client = ASLClient()
let query = ASLQueryObject()
query.setQueryKey(.Sender, value: productName, operation: .EqualTo, modifiers: .None)
client.search(query) { record in
if let record = record {
// we've gotten a log entry for the search.
// 'record' is of type ASLQueryObject.ResultRecord
}
else {
// there are no more log entries to process
}
// return true while we still want to get results
// or return false when we don't want to process more
return true
}注意:在iOS设备上,ASL将只返回由您的进程生成的日志条目。此外,日志被相当积极地修剪,并且可能只包括您的应用程序当前运行时生成的条目。在Mac/iOS模拟器上和在iOS设备上的ASL行为之间的进一步差异是在此解释。
https://stackoverflow.com/questions/16068095
复制相似问题