Viewing os_log messages in device console
The "Devices and Simulators" window only shows crash reports. Use the Console app or Terminal, via the log --stream
command, to see live log output.
To see the device's live log messages via the Console app, either when running from Xcode or when running from the device directly:
- Open Console.app.
- Click on the device's name in the left side panel, under "Devices".
- Select Action, then Include Info Messages from the menu. If you are also using
.debug
level messages, make sure to select Include Debug Messages as well. (Without those items selected, the Console displays.default
,.fault
, and.error
level messages only.)
If you still don't see the messages, try entering this Terminal command to configure the logging levels for your app:
sudo log config --subsystem com.test.testapp --mode level:debug
This turns on .debug
-level logging for subsystem "com.test.testapp" (which includes .info
and .default
messages).
If you want to persist the messages, rather than the default of memory-only, turn on persistence for the three levels at the same time, like so:
sudo log config --subsystem com.test.testapp --mode level:debug,persist:debug
Regardless of any log settings, though, only crash reports will appear in the "Devices and Simulators" window.
how to see iOS device logs in Console app using os_log
This is not a complete answer, but a large part of the trick seems to be this:
In Xcode's Devices and Simulators window, locate the device and show the console display by tapping the tiny button at the lower left.
It appears that this somehow opens the floodgates and allows the stream of log events to pass through to the Console app. It still isn't 100% reliable; eventually the stream can be mysteriously shut off, and I have the impression that events are randomly omitted now and then. But it seems to be a sine qua non for getting the stream to flow at all.
Swift macOS App - Enable Info/Debug Logging in Apple Console App
I faced the same problem. Info and debug level messages must be activated in the Console application: Console
> Action
> Include Info Messages
and Include Debug Messages
.
Take a look at Apple documentation at Include info or debug messages.
Only Crash logs showing in Device Console
(Swift 5.3, Xcode 12, iOS 14 — No need for a third party service or library)
In short: You can replace your NSLog
calls with calls to Logger
.
You need to create a Logger
object (somewhere, your preference). If you want, you can make your logging easier to filter, e.g. in the Console app, by making various loggers for different parts/functions in your app.
import os.log
let downloadLogger = Logger(subsystem: "My app", category: "Downloading")
let somethingLogger = Logger(subsystem: "My app", category: "Lorem ipsum")
Then you call your logger like this:
// Some error occurs, so we log it:
downloadLogger.error("Error downloading feed contents: \(error, privacy: .public)")
// Some less important log:
somethingLogger.info("Secret has been stored: \(mySecret, privacy: .private(mask: .hash))")
N.B. our secret is kept secret by applying .private(mask: .hash)
.
To view and filter your logs, on the Devices screen, below the View Device Logs you'll find Open Console.
As the article source states:
"If you’d like to gather logs from a device, even when your app is not
running anymore, you can use thelog
command on your Mac with thecollect
option
…
Thelogarchive
file that you get can then be opened in the Console app and filtered just like live logs can."
sudo log collect --device --start "2020-06-25 16:10:00" --output myapp.logarchive
(Credits: source)
Related Topics
Find Delegate in a Swift Array of Delegates
Swift 2 - Separating an Array into a Dictionary with Keys from a to Z
Swift - Nsdate and Last Week of Year
Mysterious "Cryptographic Verification Failure" Error on MACos Sierra, Xcode 8
Square Video Using Avfoundation
Your Credentials Do Not Allow Access to This Resource Twitter API Error
Non-Main Bundle File as Alert Sound
Uibezierpath + Cashapelayer - Animate a Circle Filling Up
Modeling Sub-Collections in Mongodb Realm Sync
Storyboard Localization in Swift 4.0
Video with Gpuimagechromakeyfilter Has Tint When Played in Transparent Gpuimageview
Pausing Timer When App Is in Background State Swift
How to Create an Image of Specific Size from Uiview
Can't Copy File from Bundle to Documents Directory in iOS