How to disable Loggings of Apptentive in Xcode console? - ios

Apptentive seems like a good addition to have. However it pollutes the Console with so many messages, that is unnecessary to see every time. It is distracting me from seeing important debug messages elsewhere.
Only an extract:
2015-05-10 10:15:45.134 xNews[34355:4228197] Loading ATSwizzle_NSObject_Bootstrap
2015-05-10 10:15:45.134 xNews[34355:4228197] Loading ATSwizzle_UIViewController_Bootstrap
According to the docs it's possible to disable them:
#import "ATConnect_Debugging.h"
[ATConnect sharedConnection].debuggingOptions = ATConnectDebuggingOptionsNone;
This doesn't work at all. I still get to see all those debug messages I don't care about. Any advice please?

The Apptentive debuggingOptions property does enable/disable some debug features, however it's true that we aren't tying that in with the log levels.
// #import "ATConnect_Debugging.h"
[ATConnect sharedConnection].debuggingOptions = ATConnectDebuggingOptionsNone;
I will make a note to add a new debuggingOptions option to silence all logging for an upcoming version of the SDK.
Apptentive does allow control over log levels via the ATLog.h file and preprocessor macros:
AT_LOGGING_ENABLED = 1
AT_LOGGING_LEVEL_INFO = 1
AT_LOGGING_LEVEL_DUBUG = 1
AT_LOGGING_LEVEL_WARNING = 1
AT_LOGGING_LEVEL_ERROR = 1
By default, release configuration of the Apptentive SDK will log only the warning and error log levels. Debug builds will log the more verbose info and debug levels.
In your Xcode project you should be able to set AT_LOGGING_ENABLED = 0 to silence all Apptentive warning. Or toggle the log levels as you see fit.
Thanks for using Apptentive! Let me know if you need any assistance with this.

Related

Unable to set a symbolic breakpoint to some Classes

I had to investigate when a certain cookie was being set but unfortunately, I couldn't figure it out just seeking in the codebase. So as usual, when the game gets tough, I go and set a symbolic breakpoint. This time, against all odds, I wasn't able to.
In particular, I have been trying to set a symbolic breakpoint to the NSHTTPCookieStorage method setCookie: and neither from the Breakpoint navigator nor from the debug console I couldn't manage to set it.
For example:
(lldb) br set -F '-[NSHTTPCookieStorage setCookie:]'
Breakpoint 6: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
I have also tried to set the Module (Foundation) but nothing changed. The same happened also for the NSURLSession method downloadTaskWithResumeData:completionHandler: Then I tried with some other Foundation's classes and it always worked, except for all of those who are part of this group inside the Apple Documentation as NSHTTPCookieStorage and NSURLSession.
I thought it could be related to some security concerns but I also remember I applied a symbolic breakpoint to some Keychain and SecKey's symbols.
Did anyone else experience the same? I haven't found any doc where something similar was mentioned.
I do get a resolved bp in my case with the same:
br set -F '-[NSHTTPCookieStorage setCookie:]'
command (side note b '-[NSHTTPCookieStorage setCookie:]' would work to).
It seems in your case lldb has not loaded CFNetwork for whatever reason.
Mine
image lookup -vn '-[NSHTTPCookieStorage setCookie:]'
yields
1 match found in /Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork:
Address: CFNetwork[0x0000000181478fbc] (CFNetwork.__TEXT.__text + 51832)
Summary: CFNetwork`-[NSHTTPCookieStorage setCookie:]
Module: file = "/Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork", arch = "arm64"
Symbol: id = {0x00000af7}, range = [0x00000001b6628fbc-0x00000001b6629020), name="-[NSHTTPCookieStorage setCookie:]"
If you're on real device try
image add '/Users/myusername/Library/Developer/Xcode/iOS DeviceSupport/12.4.1 (16G102)/Symbols/System/Library/Frameworks/CFNetwork.framework/CFNetwork'
(obviously path substitute for appropriate iOS version^)
If you're on simulator try
image add '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CFNetwork.framework/CFNetwork'
If you don't get an error then try setting your symbolic breakpoint at that point.

Show debug messages if argument is set

In my project i'm showing debug messages with global variable:
struct GVariables {
static let debug = false
}
if GVariables.debug {
print("Debug mode enabled")
}
But is it possible to set argument here:
and check debug argument in code. How can i do this ? And is this a correct way ?
You can get access to those launch arguments and environment variables via NSProcessInfo
if NSProcessInfo.processInfo.arguments["DEBUGRPM"] ...
That's not unreasonable and allows you to change the behavior of a compiled app which can be useful in some cases. It does however have some overhead since you're always performing this check. If you would only ever enable debug logging in a debug build then setting a value in "Swift Compiler - Custom Flags" (as shown in the question #Larme linked) and using an #if DEBUGRPM expression will give you conditionally compiled code, saving the app the work of performing a runtime if test.
Which approach is more reasonable for you will depend on how you plan to use and when you plan to toggle this behavior.

Lumberjack log DDLogInfo showing up as WARNING in console

I am using Lumberjack as my logging framework.
I have this definition…
#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_DEBUG;
#else
static const int ddLogLevel = LOG_LEVEL_WARN;
#endif
and this is my log statement…
DDLogInfo(#"Starting");
However when I look at the Console.app it shows this message as a WARNING instead of INFO like ASL can show. Is there something else that I need to do?
This does allow the statement to not be logged when not in DEBUG mode, so that is working as advertised.
This is the expected behavior.
The DDASLLogger map the Debug to ASL's Warning level, Info to Error etc.
Thats because by default, ASL will filter Notice level and above.
(In case DDLogInfo prints Warning, then you are using an older version of CocoaLumberjack)
Apple System Log documentation says:
The default filter mask is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
This means that by default, and in the absence of remote-control changes
(described below), ASL_LEVEL_DEBUG and ASL_LEVEL_INFO priority level messages
are not sent to the server.
You could try and write your own custom ASL logger.
But I suggest that you will add a custom formatter to the ASL logger that will add the actual log level (faster approache).

Turn logging to lldb console off (Socket IO framework for iOS)

I am using pkyeck / socket.IO-objc framework. It is very good, however I am unable to debug with the verbose logs it produces to the lldb, which makes the console constantly full with descriptions about traffic, which are useless to me at the moment. I couldn't find a way how to turn it OFF. Anybody knows how to do it? I just can't imagine myself commenting out all the lines with NSLog...
Found the solution. It is rather undesired to tinker with the source code of the framework - usually it is a good practice to take it AS-IS but since there wasn't any other way...
In the file SocketIO.m, locate line numbers 32 - 39:
#define DEBUG_LOGS 1
#define DEBUG_CERTIFICATE 1
#if DEBUG_LOGS
#define DEBUGLOG(...) NSLog(__VA_ARGS__)
#else
#define DEBUGLOG(...)
#endif
Naturally, everybody now knows what comes next - change the value of DEBUG_LOGS to 0.
That's it, done. I recommend adding a //TODO: to the line above in order not to forget for the next time, when debugging logs are desired.

string value always shows nil in objective C

I have upgraded to Xcode 5.0. And when I run an app in debug mode and try to print an NSString value in console, it gives me the below error. Any ideas?
error: warning: couldn't get cmd pointer (substituting NULL): Couldn't load '_cmd' because its value couldn't be evaluated
Couldn't materialize struct: the variable 'stringValue' has no location, it may have been optimized out
Errored out in Execute, couldn't PrepareToExecuteJITExpression
Here is the code:
NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:#"merchant_name"];
The reason is stated in the error message: it may have been optimized out.. this means that you are compiling and running your code in an optimized manner.
you gotta change your compiler optimization level from Fastest,Smallest to none:
go to your target build settings
search for optimization level
change it to none (whatever mode you are in ie debugging, distribution or release)
profit
do the same for your project settings
Make sure you are in debug mode. Go Edit Scheme > Build Configuration > Debug
You might be trying to debug in the "release Scheme". Go to "Product/Scheme/Edit Scheme" and pick the "run" in the left panel. Then change the build configuration to "debug".
One alternate answer: instead of fixing "it may have been optimized out" by removing the optimization, you can stop it from being optimized by using the variable.
So, in your question, if you do something with stringValue:
NSString *stringValue = [[self.responseArray objectAtIndex:i] valueForKey:#"merchant_name"];
NSLog(#"%#", stringValue);
stringValue will no longer be optimized out because you're using it.
If you want to see all instances of optimized-out variables in your project, Use Product -> Analyze to analyze your project. Any "Dead store" warnings (in which a value is stored, and never read) will be optimized out at compile time if you have compiler optimization turned on.

Resources