iOS Tracker logging to Xcode Debugger

Hi! Do we have a logging mechanism for iOS tracker that will print to Xcode debugger output? Android has this API .level(LogLevel.VERBOSE) but I can’t find one for iOS. I’ve already checked the documentation. Would appreciate any insights about this. Thanks!

I am guessing that NSLog | Apple Developer Documentation does not work for you. If so why?

Hi @teffi if you are talking about turning on tracking out of the Objc SDK this is likely the macro you are looking for:

https://github.com/snowplow/snowplow-objc-tracker/blob/master/Snowplow/Snowplow.h#L41-L47

It doesn’t have the same flexibility or control as Android unfortunately but the presence of that macro should turn logging on.

1 Like

@Konstantinos_Servis I’m referring to a possible Snowplow API that can be turned on to auto log the payload it sends to the collector. The success/fail protocol doesn’t expose the payload to be printed via NSLog.

@josh Will check that out. Thanks!

Oh right I misunderstood completely @teffi and TIL there is a logging macro! Thanks

1 Like

**Edit:
It’s now working. Since I’m using pods, the macro should be placed on the pod target not the project target. I used Cocoapod post_install hook to insert the macro so it would be built properly on every pod update or install.

@josh Added the macro but still I’m not seeing any SPLog on the debugger.
Project supports both Objc and Swift.

1 Like

Thanks for the update @teffi! Will make sure this all gets added to our documentation.

1 Like

@josh Cool. Already saw the github issue for this.

To those who wants a better logging approach.
In my case I made an additional breakpoint logging on the SPEventStore methods below to get unescaped readable payload. I can’t prettify it directly on Xcode debugger because it gets trimmed so I use text editors like Sublime to do that.

Note: Disable encoding when debugging and enable on release.

Command (copy paste version):
po for (NSString *itemd in dict) { NSDictionary *abc = [NSJSONSerialization JSONObjectWithData:[((NSString*)dict[itemd]) dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONWritingPrettyPrinted error:nil]; if (abc == nil) { NSLog(@"SPLogCustom: %@ - %@", itemd, dict[itemd]);} else { printf("SPLogCustom: %s\n", [NSString stringWithFormat: @"%@ - %@", itemd, dict[itemd]].UTF8String); }}

Readable version:

for (NSString *itemd in dict) {
    NSDictionary *abc = [NSJSONSerialization JSONObjectWithData:[((NSString*)dict[itemd]) dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONWritingPrettyPrinted error:nil];
    if (abc == nil) {
        printf("SPLogCustom: %s\n", [NSString stringWithFormat: @"%@ - %@", itemd, dict[itemd]].UTF8String);
    } else {
        NSLog(@"SPLogCustom: %@ - %@", itemd, abc);            
    }
}

It gives you something like this

SPLogCustom: p - mob
SPLogCustom: uid - 58
SPLogCustom: co -  
{"schema":"iglu:com.snowplowanalytics.snowplow\/contexts\/jsonschema\/1-0-1","data":[{"schema":"iglu:com.snowplowanalytics.snowplow\/mobile_context\/jsonschema\/1-0-1","data":{"osType":"ios","appleIdfa":"sample idfa","osVersion":"12.2","appleIdfv":"sample idfv","deviceManufacturer":"Apple Inc.","networkType":"wifi","deviceModel":"iPhone"}},{"schema":"iglu:com.snowplowanalytics.mobile\/application\/jsonschema\/1-0-0","data":{"build":"25244","version":"0.9.0"}},{"schema":"iglu:com.snowplowanalytics.snowplow\/client_session\/jsonschema\/1-0-1","data":{"previousSessionId":"sample previous session id","firstEventId":"first event id","sessionId":"sample session id","userId":"sample uid","sessionIndex":104,"storageMechanism":"SQLITE"}},{"schema":"iglu:com.snowplowanalytics.mobile\/screen\/jsonschema\/1-0-0","data":{"topViewController":"controller","id":"event id","name":"controller","type":"Default","viewController":"controller"}}]}
1 Like