使用新的swift os_log api读取日志 [英] Read logs using the new swift os_log api

查看:926
本文介绍了使用新的swift os_log api读取日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 10.0中已弃用:os_log(3)已替换asl(3)

Deprecated in iOS 10.0: os_log(3) has replaced asl(3)

因此iOS 10.0显然弃用了asl(Apple系统日志)API并将其替换为非常有限的os_log api。

So iOS 10.0 apparently deprecates the asl (Apple System Log) api and replaces it with the very limited os_log api.

我使用类似于下面代码片段的内容来读取正在运行的应用程序的日志写入,以便在应用程序的uitextview中显示 - 现在它充满了弃用警告。有没有人知道使用新的os_log api读取打印日志的方法?因为我只看到写作的api( https://developer.apple.com/reference/ os / 1891852-logging )。

I use something similar to the code snippet below to read out log writes for the running app to show in a uitextview in app - and now it is full of deprecation warnings. Does anyone know of a way to read the printed log using the new os_log api? Because I only see an api for writing (https://developer.apple.com/reference/os/1891852-logging).

import asl

let query = asl_new(UInt32(ASL_TYPE_QUERY))
let response = asl_search(nil, query)
while let message = asl_next(response) {
    var i: UInt32 = 0
    let key = asl_key(message, i)
    print(asl_get(message, key))
    ...
}



编辑@Will Loew-Blosser的回答



https://developer.apple.com/videos/play/wwdc2016/721/ 很好地解释了将来登录会发生什么。最大的赠品是日志以某种压缩格式放置,只能由新的控制台应用程序扩展。这几乎使我的任务无望。

Edit after @Will Loew-Blosser's answer

https://developer.apple.com/videos/play/wwdc2016/721/ explained nicely what is going to happen with logging in the future. The biggest giveaway was that logs are put in some compressed format and only expanded by the new Console application. Which pretty much makes my mission hopeless.

视频中的人(Steve Szymanski)提到所有ASL日志API都被新API取代和用于搜索的新API新发布的日志数据不会公开发布aka asl_search 。而这正是我所寻找的!

The guy (Steve Szymanski) in the video mentions "All ASL logging APIs are superseeded by new APIs" and "New APIs for searching new log data will not be made public this release" aka asl_search. And that was exactly what I was looking for!

他还提到了我即将推出的快速API。

Also he mentions that a swift API i coming.

推荐答案

看起来您需要使用增强型控制台而不是您自己的日志查看器。日志被压缩,直到查看才会展开 - 这使得日志记录在调试级别上的干扰更少。但是没有日志的文本形式。

Looks like you need to use the enhanced Console instead of your own log viewer. The logs are compressed and not expanded until viewed - this makes logging much less intrusive at debug levels. There is no text form of the logs however.

请参阅2016 WWDC视频会话721统一记录和活动跟踪 https://developer.apple.com/videos/play/wwdc2016/721/

See the 2016 WWDC video session 721 "Unified Logging and Activity Tracing" https://developer.apple.com/videos/play/wwdc2016/721/

演示新方法的Apple示例应用程序还有一个未记录的构建设置,我必须添加到我的iOS应用程序中。请参阅Paper Company(Swift)iOS应用中的设置。
该设置位于顶级xCode窗口的Targets部分。这些是我遵循的步骤:

Also the Apple sample app that demos the new approach has an undocumented build setting that I had to add to my iOS app. See the setting in the 'Paper Company (Swift)' iOS app. The setting is found in the Targets section of the top level xCode window. These are the steps that I followed:


  1. 在Build Settings页面上添加User-Defined一个新的section = ASSETCATALOG_COMPRESSION 。

  1. On the Build Settings page add in "User-Defined" a new section = ASSETCATALOG_COMPRESSION.

在其下添加两行:

调试=无损

发布=尊重资产目录

添加此构建设置后,登录工作在我的应用程序根据视频会话演示。

After adding this build setting then logging worked in my app as per the video session demo.

这篇关于使用新的swift os_log api读取日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆