Add logs in xCode console with ASL - ios

I have implemented logging functionality with ASL. And I can see logging in the Console application in MAC OS. Is there any way by which I can see console logs produced by ASL Logger redirected in Xcode Console?
I have opened ask by below statement.
asl_open(NULL, "com.apple.console", 0);
which is logging in apple's console. can I change in above statement and get the logging in Xcode's console.

Related

How to use Console.app to view debug-level logs from os_log from an iOS app running in the Simulator?

This is a question about how to use Apple's Unified Logging framework, also known as "os_log", the function you call from Swift.
Specifically, I want to know if it is possible:
to view logs in Console.app (not with the log command line tool) ...
to see debug-level logs (not just info-level logs) ...
for an iOS app running in the Simulator (not just running on a device).
You cannot do this just by running Console.app, pointing at the Simulator, and selecting Action / Include Debug Message, which is the obvious thing to do.
This article suggests that debug-level logs don't show up because "the 'system' log level is set to info" but I can't find a discussion anywhere that explains what that means.
This appears to be a bug in the Console app when dealing with the simulator: https://forums.developer.apple.com/thread/82736
I believe a Radar has been logged: rdar://47667447

Viewing os_log messages in device console

I'm trying to get some logging out of my app through Unified Logging (os_log)
Here's the initialization of the log:
var osLog : OSLog = OSLog(subsystem: "com.test.testapp", category: "native-tester")
And here's how I use it:
os_log("iOS App initialized successfully!", log: osLog, type:.info)
When debugging the app normally, the logs appear properly on the console output, but when I look at the device console (Shown in the "Devices and Simulators" window) I don't see them at all.
This article says that you should configure the system to enable the debug logs using
sudo log config --mode "level:debug" --subsystem com.test.testapp
But that didn't seem to make a difference. I'm guessing it's because I'm configuring the mac to view the logs, not the iPad.
How do I view the ipad / iphone logs from os_log in the 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.
Another pitfall: If you have set OS_ACTIVITY_MODE to disable in your scheme, then you will not see any logs for your app in console.
You have to remove or uncheck that argument.
Log types .debug and .info are by default memory only (not saved on disk) so it won't be visible on the device console.
Detailed info:
https://developer.apple.com/documentation/os/logging?language=objc
Also here is pretty nice WWDC:
https://developer.apple.com/videos/play/wwdc2016/721/
In the console app, there are two options to include / hide debug and info messages:
Following screenshots could be helpful for reference-
My os_log went missing after releasing an app to app store. I guess when I built the app for release, the debug option was turned off.
To enable the logging back... go to Product > Scheme > Edit Scheme > Run Debug ... then check Debug executable.

Info and Debug Unified Logging messages not appearing in console when running iOS simulator

I can't see Debug level or Info level log messages in the console app when running from the the iOS simulator.
I can see Default, Error and Fault levels in the console with the simulator.
I can see all Debug, Info, Default, Error and Fault levels in the console with a real non-simulated device.
I'm using the same console app filter settings with the simulator and in a real device.
I'm using XCode 8.3.3 with a simulator running iOS 10.3.
I'm using the Unified Logging System in my iOS app, as described here:
https://developer.apple.com/documentation/os/logging
https://developer.apple.com/videos/play/wwdc2016/721/
How can I get these Debug level and Info level log messages to display when running against the simulator?
In the Console app's menu:
Action ->Include Info Messages and/or ->Include Debug Messages
Update:
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.mydomain.appname --mode level:debug
This turns on .debug-level logging for subsystem "com.mydomain.appname" (which includes .info and .default messages).
Separately, 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.mydomain.appname --mode level:debug,persist:debug
(subset of my answer at Viewing os_log messages in device console)
This seems to be the expected behaviour, unfortunately I can't point to any documentation to back this up, however the Info and Debug level log messages are sent to Xcode's console, not the Console.app.

Change the log level on iOS 10 (Unified Logging) with Console.app

This is so simple but: how on earth do I set the level of log messages I see in Console.app, if I am trying to use iOS10's new "Unified Logging & Activity Tracing" API?
In other words, if I have code running on iOS like so:
fileprivate let logger = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "mycategory")
fileprivate func logv(_ s:String) {
os_log("%#",log:logger,type:.info,s)
}
Then what do I need to do to see the logged messages in Console.app? By default, only log messages of type .error seem to show up.
I am wondering how to do this if I am running code on a device, not in the simulator.
Related:
Xcode 8 - os_log_debug and os_log_info logs are not displayed on new Mac console (unified logging)
Hilariously, the answer is that you just go to the Console.app's menu bar and select:
Action / Include Info Messages
Action / Include Debug Messages
Xcode 10.0 beta 6 (likely others too) won’t show debug messages logged from the simulator even after enabling Include Info Messages, Include Debug Messages in the Console.app. AFAIK there is no fix for this.
To see debug logs sent from the simulator you have to stream from a terminal instead:
xcrun simctl spawn booted log stream --debug --predicate 'subsystem == "es.com.jano.Myapp"'

iOS running app from xcode show me a message to enable debug logging

when I start my app from xcode 7 I see this message
2016-01-14 13:50:13.119 Guggy[31879:] <GMR/INFO> To enable debug logging
set the following application argument: -GMRDebugEnabled (see http://goo.gl/Y0Yjwu)
I tried to follow their instructions in the link but it still show me this message.
What am I doing wrong?
You are not doing anything wrong.
The message " To enable debug logging ..." is always showing up regardless if you have the debug logging enabled or not.
If you want to check whether you enabled the debug logging, you should look for the following message: " Debug logging enabled".
Use -noGMRDebugEnabled to disable the debug logging.

Resources