Why aren’t my Safari App Extension NSLog messages showing up in the console in Xcode?
<p>I’m following <a href="https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/SafariAppExtension_PG/CreatingandTestingYourFirstSafariAppExtension.html#//apple_ref/doc/uid/TP40017319-CH11-SW1" rel="noreferrer">Apple’s guide for creating a Safari App Extension</a>. In short, I’ve:</p>

<ul>
<li>Created a new Xcode project (in Xcode 8.1, on macOS 10.12 Sierra) using the Cocoa Application template</li>
<li>Created a new target in the app using the Safari Extension template</li>
<li>Run the app once, to make sure the Safari App extension is built</li>
<li>Selected the “Allow Unsigned Extensions” option in Safari’s Develop menu</li>
<li>Enabled the extension in Safari’s Extensions preference pane</li>
</ul>

<p>The extension’s toolbar button appears in Safari. Apple’s guide says I should see the NSLog message in the console when I click the toolbar button, but I’m not seeing anything.</p>

<p>I’ve edited SafariExtensionHandler.swift to send a message to the script injected by the extension:</p>

<pre><code>override func toolbarItemClicked(in window: SFSafariWindow) {
    // This method will be called when your toolbar item is clicked.
    NSLog("The extension's toolbar item was clicked")

    window.getActiveTab(completionHandler: { (activeTab) in
        activeTab?.getActivePage(completionHandler:  { (activePage) in
            activePage?.dispatchMessageToScript(withName: "toolbarItemClicked", userInfo: nil)

        })
    })
}
</code></pre>

<p>And I’ve edited the injected script (script.js) to alert that message:</p>

<pre><code>safari.self.addEventListener("message", function (event) {
    alert("We got a message from the extension! - " + event.name + ": " + event.message);
});
</code></pre>

<p>The alert appears when I click the toolbar button (when I’m on a page on webkit.org, as I’ve left in the default SFSafariWebsiteAccess settings), so the extension is working and registering the click. But I don’t see the NSLog in Xcode’s console, or the Console app.</p>

<p>I’m a real Xcode newbie, so I’m sure I’m missing something obvious — but why isn’t the NSLog message appearing in the console?</p>

<p>(I don’t run as an administrator, in case that makes a difference — although I did enter the administrator account details whenever I was asked to whilst running Xcode for the first time. I do notice that in the Console app, when I select system.log, I just see a message saying “Unable to read the file”. This <a href="https://discussions.apple.com/thread/7701968?start=0&amp;tstart=0" rel="noreferrer">might be related to not running as an administrator</a>.)</p>