Reading Apple Watch syslog (NSLog()) in real-time

我怕爱的太早我们不能终老 提交于 2019-12-12 06:05:36

问题


I'm looking for a way to read the watch's syslog in real-time, similar to the way Device Console or this do it for the iPhone.

It's ok if the phone will be plugged by usb to the computer at the time I'm reading.

At this point I'll even settle for a solution that somehow reads the texts at real-time from Xcode debug console, really (though I will prefer a way to hook in to the watch's syslog in a standard fashion :)..

Thanks!


回答1:


While I couldn't find any official way to get logs from the device, I did manage to write a hack that does so in real time.

It uses a python GUI automation library to pull the text from the Xcode console window.

Please notice this solution does have it's limitations, as it:

  • requires the phone to be connected to the computer via cable
  • only contains the logs from your own app, thus it falls short of the tools mentioned earlier.

However, it did solve my problem and I'm publishing the short python code in the hopes that it will help other developers.

import atomac

def get_console():
    xcode = atomac.getAppRefByBundleId('com.apple.dt.Xcode')
    return xcode.windows()[0].groups()[0].textAreasR()[1]

def run():
    console = get_console()
    while True:
        clog = console.AXValue[-1000:]
        last_read = clog.split("\n")[-2]
        print last_read

if __name__ == "__main__":
    run()

Notice you may have to play with some of the indexes inside get_console() to get the console window in your Xcode setup.

(If you're interested, this hack code was written for a hackathon project, as a way to get fast data from the watch since it couldn't send any UDP packets on WatchOS2 Beta 4 and the official ways of sending data from the watch [such as sendMessageData:replyHandler:errorHandler:] were too slow for what we needed).




回答2:


I know this is an old thread, but for anyone who lands on this search, there is way to do this: https://forums.developer.apple.com/thread/94693.

To summarize, load a diagnostic profile onto the watch, (link in the forum post,) then you can use MacOS system console to see the watch messages. Right now I'm having a strange issue where some of the messages I NSLog() appear and others don't, but you can see the watch messages in real time.



来源:https://stackoverflow.com/questions/31826382/reading-apple-watch-syslog-nslog-in-real-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!