Log Collection

The SDK records logs for all the operations that it performs once it is initialized. It displays all the logs in a console when the application is running.

It is mandatory for the host application to implement the log API, so that in case of issues it will print the logs in the console.

There is a protocol called iPassLogger in the SDK, which has three methods to print the log in the console. Its host application has the responsibility to conform to that protocol.

Recommendation

Here the SDK is in objective-c language.To import a set of Objective-C files in the same host application target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift.

Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.

 

If you accept, Xcode creates the header file along with the file you were creating, and names it by your product module name followed by adding "-Bridging-Header.h".

In your Objective-C bridging header file, import every Objective-C header you want to expose to Swift. For example use #import "Logger.h" if you are creating a swift project otherwise not required to import this file on objective-C project.

Create a cocoaTough class Logger which inherits from NSObject and conforms to the iPassLogger protocol.

Implement the following methods in logger class to print the logs in the console ; For example:

#import "Logger.h"
  -(void)logWithLevel:(SMCLogLevel)level format:(NSString*)format, ... {
}

-(void)logWithLevel:(SMCLogLevel)level message:(NSString*)message {
    NSLog(@"%@", message);
}

-(void)logUserDebugInfoWithType:(SMCLogLevel)type format:(NSString*)format {
    NSLog(@"%@", format);
 }

 

These methods will print the logs in the console and host application needs to ensure to store these logs in file.

For example the below code shows to store the logs in some under the document directory.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

   NSString *dsdebugPath = [NSString stringWithFormat:@"%@/dsdebug.txt", [paths objectAtIndex:0]];

   freopen([dsdebugPath UTF8String], "a+", stderr);

 

 

Customizing the UILocalization