{"id":545,"date":"2017-09-29T02:16:58","date_gmt":"2017-09-29T02:16:58","guid":{"rendered":"http:\/\/fluentreports.com\/blog\/?p=545"},"modified":"2017-10-03T06:12:13","modified_gmt":"2017-10-03T06:12:13","slug":"nativescript-and-console-logging-on-ios-including-xcode-9","status":"publish","type":"post","link":"http:\/\/fluentreports.com\/blog\/?p=545","title":{"rendered":"NativeScript and Console logging on iOS (including XCode 9)"},"content":{"rendered":"<p>Been a while since I posted; and most this info was going to be presented at the NativeScript Developer days speech that we ran out of time in our cool session.\u00a0\u00a0\u00a0\u00a0 So I'm going to present it here, because I think this will help a lot of people.<\/p>\n<p>First of all, NativeScript has an issue (at least on my machine) where the logging is <a href=\"https:\/\/github.com\/NativeScript\/nativescript-cli\/issues\/3106\">incomplete<\/a> and missing important things, like <a href=\"https:\/\/github.com\/NativeScript\/nativescript-cli\/issues\/3105\">crash reports<\/a> (and now on<a href=\"https:\/\/github.com\/NativeScript\/nativescript-cli\/issues\/3118\"> XCode 9, non-existent<\/a>).<\/p>\n<p>Well, when I ran into the two first issues using XCode 8.2 &amp; 8.3. \u00a0 I figured out a work around, because I hate my tools not working.\u00a0\u00a0\u00a0 \ud83d\ude42<\/p>\n<p>There is a really awesome set of utilities called <a href=\"http:\/\/www.libimobiledevice.org\/\">libimobiledevice<\/a> this set of utilities lets you do all sorts of things with a real iphone when it is connected to your computer including reading the logs.<\/p>\n<p>&nbsp;<\/p>\n<h2>Real Devices (any version of iOS)<\/h2>\n<p>So I typically do <span style=\"color: #0000ff;\"><strong>idevicesyslog | grep CONSOLE<\/strong><\/span> and it will then show me all my logs for the device and it basically fixes any issues other than some exception reporting.\u00a0\u00a0 Most the time my app doesn't crash so that command above I use probably 99% of the time.\u00a0\u00a0\u00a0 However in the cases I need to see the NativeScript actual crash logs. \u00a0 I use the above command and it will spit out the PID of your app next to the CONSOLE word.\u00a0 I then cancel it, and do a <strong><span style=\"color: #0000ff;\">idevicesyslog | grep &lt;PIDID&gt;<\/span><\/strong> and this gives me the full log including anything the NativeScript runtimes print.<\/p>\n<p>Please note this only works for real devices.<\/p>\n<h2>Simulators (iOS 10 and before)<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>UPDATE for iOS 11 simulators, please see below!<\/strong><\/span><\/p>\n<p>Now for simulators; the process is very similar.<\/p>\n<p>You run <span style=\"color: #0000ff;\"><strong>xcrun simctl list | grep Booted<\/strong><\/span> and it will give you a line like this:<br \/>\niPhone X (<em>4701B6F6-0EE4-423F-B5E2-DE1B5A8C32AC<\/em>) (Booted)<\/p>\n<p>Do you see that big old long <em>uuid<\/em>; you need that.<\/p>\n<p><span style=\"color: #0000ff;\"><strong>tail -f ~\/Library\/Logs\/CoreSimulator\/<\/strong><em>4701B6F6-0EE4-423F-B5E2-DE1B5A8C32AC<\/em><strong>\/system.log | grep CONSOLE<\/strong><\/span><\/p>\n<p>This allows you to grep the log from that specific simulator.\u00a0\u00a0 Again, using the <strong>grep CONSOLE<\/strong> filter you can limit it to any console logs.\u00a0\u00a0 And you can also use <strong>grep &lt;PIDID&gt;<\/strong> to filter it to any application if you need the filtered down to, if you are needing the specific NativeScript application level logging or crash reports too.<\/p>\n<p>&nbsp;<\/p>\n<h2>Simulators (iOS 11)<\/h2>\n<p>iOS 11, changed the logging for the Simulator drastically.\u00a0 Technically iOS 10 changes the NSLog drastically, but 11 enforced some new rules.\u00a0\u00a0 So iOS 11 broke the NativeScript internal logging; but it broke the cool <span style=\"color: #3366ff;\"><strong>tail<\/strong> <\/span>trick above. \u00a0\u00a0 Everything now is now running through the new <strong>os_log<\/strong> facility.\u00a0 The easiest way to get logging from your simulator is this single line:<\/p>\n<p><strong><span style=\"color: #0000ff;\">log stream --level debug --predicate 'senderImagePath contains \"NativeScript\"'<br \/>\n<\/span><\/strong><strong><span style=\"color: #0000ff;\">--style syslog<\/span><\/strong><\/p>\n<p>Please note this is case sensitive, if you don't case the <em>senderImagePath<\/em> and <em>NativeScript<\/em> you won't have your filtered logging (or any logging at all if you type it wrong).\u00a0\u00a0 This part of it filters it down to just any NativeScript logging from all emulators running.<\/p>\n<p>I created a simple bash script called \/usr\/bin\/local\/tnslog and dropped the above line it in and then <span style=\"color: #0000ff;\"><strong>chmod +x \/usr\/local\/bin\/tnslog <\/strong><\/span>'d it.\u00a0 So I can easily just start tns, and then open another terminal tab; and type <span style=\"color: #0000ff;\"><strong>tnslog<\/strong> <\/span>and have all my logging again.<\/p>\n<p>&nbsp;<\/p>\n<h2>Installation<\/h2>\n<p>The simulator you need no extra tools.\u00a0\u00a0 For real devices you need the libimobiledevice toolset, which you can easily install via brew with the following two commands:<\/p>\n<p><span style=\"color: #0000ff;\"><strong>brew install --HEAD usbmuxd<\/strong><\/span><\/p>\n<p>and<\/p>\n<p><span style=\"color: #0000ff;\"><strong>brew install --HEAD libimobiledevice<\/strong><\/span><\/p>\n<p>It is really important that you install from <strong>head<\/strong>, the changes in Xcode 9 and iOS 11 have made a couple changes to both those libraries require some updates and the normal brew packages are out of date and doesn't have it.\u00a0 So you need the latest and greatest.<\/p>\n<p>&nbsp;<\/p>\n<h2>Final Thoughts<\/h2>\n<p>I have been lazy, and just documented the steps.\u00a0\u00a0 If someone has some spare time and wants to create a quick bash script to automate the grabbing of the simulator id, and starting the older logging; against that simulator that would be cool to add to our tools.\u00a0 But since I'm using primarily iOS 11 emulators now; my tnslog script handles all logging until the NativeScript team can fix their tool's issues.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Been a while since I posted; and most this info was going to be presented at the NativeScript Developer days speech that we ran out of time in our cool session.\u00a0\u00a0\u00a0\u00a0 So I'm going to present it here, because I think this will help a lot of people. First of all, NativeScript has an issue&hellip; <a class=\"more-link\" href=\"http:\/\/fluentreports.com\/blog\/?p=545\">Continue reading <span class=\"screen-reader-text\">NativeScript and Console logging on iOS (including XCode 9)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[15,39],"tags":[52,107,16,43],"class_list":["post-545","post","type-post","status-publish","format-standard","hentry","category-nativescript","category-tips","tag-ios","tag-logging","tag-nativescript","tag-xcode","entry"],"_links":{"self":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=545"}],"version-history":[{"count":4,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":549,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions\/549"}],"wp:attachment":[{"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fluentreports.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}