Logging

It's best to change the log level early on, for example in -[UIApplicationDelegate application:didFinishLaunchingWithOptions:].
The default log level is PSPDFLogLevelMaskWarning|PSPDFLogLevelMaskError.

Copy
1
2
// Change log level to be more verbose.
PSPDFKit.sharedInstance().logLevel = PSPDFLogLevelMask(rawValue: PSPDFLogLevelMask.Info.rawValue | PSPDFLogLevelMask.Warning.rawValue | PSPDFLogLevelMask.Error.rawValue)!
Copy
1
2
// Change log level to be more verbose.
PSPDFKit.sharedInstance.logLevel = PSPDFLogLevelMaskInfo|PSPDFLogLevelMaskWarning|PSPDFLogLevelMaskError;

Available Log Levels:

  • PSPDFLogLevelMaskNothing
  • PSPDFLogLevelMaskError
  • PSPDFLogLevelMaskWarning
  • PSPDFLogLevelMaskInfo
  • PSPDFLogLevelMaskDebug
  • PSPDFLogLevelMaskVerbose
  • PSPDFLogLevelMaskAll

If you want to learn more about the different log levels please take a look at PSPDFLogLevelMask.

Custom Log Handler

PSPDFKit also allows you to set a custom log handler to forward logging to a different system.
By default, NSLog is used for logging. Here's how you can set a different log handler:

Copy
1
2
3
4
5
6
7
8
PSPDFKit.sharedInstance.logHandler = { level, tag, message, file, function, line in
    switch level {
    case .error:
        print("[PSPDFKit] Error in \(function): \(message())")
    default:
        print("[PSPDFKit] \(message())")
    }
}
Copy
1
2
3
4
5
6
7
8
9
10
11
[PSPDFKit.sharedInstance setLogHandler:^(PSPDFLogLevelMask level, const char *tag, NSString *(^message)(void), const char *file, const char *function, NSUInteger line) {
    switch (level) {
        case PSPDFLogLevelMaskError:
            NSLog(@"[PSPDFKit] Error in %s: %@", function, message());
            break;

        default:
            NSLog(@"[PSPDFKit] %@", message());
            break;
    };
}];

See -[PSPDFKit logHandler] for more information