Custom logs appended to user ID

Petri Kero's Avatar

Petri Kero

19 May, 2017 10:28 AM

I implement application specific logging according to this, but instead of getting the logs on the 'Description' tab, it seems to be appended to the User id reported in 'Meta' tab.

I've attached a screenshot of hot it looks like. All the text stuff after the actual ID is what I'm expecting in the logs.

Another question, when does the crash handler call userIDForHockeyManager()? In my application, I currently only have the real userId after the application has successfully logged into our servers. Everything should work fine if the userId is collected at the time of the crash, but if it's collected when sending the report, then I'd expect it to fail. I'm not currently seeing our own userIds being, but the UUID that's shown in the screenshot as well (I assume that's auto-generated by HockeyApp).

I'm using HockeySDK 4.1.4 on iOS.

  1. Support Staff 1 Posted by Shawn Dyas on 19 May, 2017 05:34 PM

    Shawn Dyas's Avatar

    Hi Petri,

    This should show up appended to the description tab, unless for some reason you are passing your logs in to userIDForHockeyManager or userID. Please provide your integration code if this is not obvious at first glance.

    For crash reports, the call to userIDForHockeyManager() is invoked on startup after a crash, it would not be reliable to attach this at the time of crash due to inherit instability. If you use [BITHockeyManager userID] property instead of the corresponding delegate method, the userID will be saved to the keychain on first initialization.

    The hash you see is attached to the report if you use anonymous authentication, it's used to identify the device for updates. You can leverage non-anonymous authentication and you can see an email address instead, please see [1].

    1. https://support.hockeyapp.net/kb/client-integration-ios-mac-os-x-tv...

    Thanks,

    Shawn

  2. 2 Posted by Petri Kero on 22 May, 2017 07:46 AM

    Petri Kero's Avatar

    I've attached the log capturing code to the end. It's basically the code you've provided, but with some minor tweaks. The contents of the log do show up, just in the wrong place. I did bump the amount of log data to 20kB from the 5kB in the example.

    The userID code is so intertwined in our own logic that I can't really extract that from the codebase. And apparently that's not working anyway, as the delegate will return nil due to the client not being logged in at the time of the crash report being sent. Is it possible that returning nil from userIDForHockeyManager() could mess up the crash report (and append the log contents into userID)?

    But did I understand you correctly that if we use the [BITHockeyManager userID], then it's enough if we set it upon successful login and let HockeyApp keep it in the keychain and correctly find it from there when it's doing the crash reporting on next app launch? If so, I'll definitely switch to that and see how things go.

    - (NSString*)getLogFilesContentWithMaxSize:(NSInteger)maxSize
    {
        NSMutableString*    description         = [NSMutableString string];
        NSArray*            sortedLogFileInfos  = [[_fileLogger logFileManager] sortedLogFileInfos];
        NSInteger           count               = [sortedLogFileInfos count];
    
        // we start from the last one
        for (NSInteger index = count - 1; index >= 0; index--)
        {
            DDLogFileInfo* logFileInfo = [sortedLogFileInfos objectAtIndex:index];
    
            NSData* logData = [[NSFileManager defaultManager] contentsAtPath:[logFileInfo filePath]];
            if ([logData length] > 0)
            {
                NSString* result = [[NSString alloc] initWithBytes:[logData bytes]
                                                            length:[logData length]
                                                          encoding: NSUTF8StringEncoding];
                [description appendString:result];
            }
        }
    
        if ([description length] > maxSize)
            description = (NSMutableString*)[description substringWithRange:NSMakeRange([description length]-maxSize-1, maxSize)];
    
        return description;
    }
    
    - (NSString*)applicationLogForCrashManager:(BITCrashManager*)crashManager
    {
        NSString* description = [self getLogFilesContentWithMaxSize:20*1024]; // send last 20kB
        if ([description length] == 0)
            return nil;
        else
            return description;
    }
    
  3. 3 Posted by Petri Kero on 22 May, 2017 11:21 AM

    Petri Kero's Avatar

    Alright, I changed to setting the userID and userName properties explicitly (and commented out the related delegate getter functions), and now everything works as expected.

    It looks a bit like there's something broken when I return nils from the userIDForHockeyManager() family of functions, but for my case, setting the variables explicitly solves the issue.

  4. Shawn Dyas closed this discussion on 22 May, 2017 05:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac