ios Logger in app and app extension problem

49 views Asked by At

Try to ligging actions in the app and extension PacketTunnelProvider. Using CocoaLumberjack In the app:

func setupLogger() {
    let appGroup = "group.some"
    
    let containerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
    let logsDirectory = containerUrl?.path
    
    let logFileManager = DDLogFileManagerDefault(logsDirectory: logsDirectory)
    let fileLogger = DDFileLogger(logFileManager: logFileManager)
    fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7
    
    DDLog.add(DDOSLogger.sharedInstance)
    DDLog.add(fileLogger)
    
    DDLogInfo("Run application \(Date())")
}

In the extension:

- (void) setupLogger {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSURL *containerUrl =
        [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.some"];
    id<DDLogFileManager> logFileManager =
        [[DDLogFileManagerDefault alloc] initWithLogsDirectory:containerUrl.path];
    
    _fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager];
    _fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
    _fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    [DDLog addLogger:_fileLogger];
    [DDLog addLogger:[DDOSLogger sharedInstance]];
}

How i read the logs:

let appGroup = "group.some"

let containerUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
let logsDirectory = containerUrl?.path

let logFileManager = DDLogFileManagerDefault(logsDirectory: logsDirectory)
let ddFileLogger = DDFileLogger(logFileManager: logFileManager)
let logFilePaths = ddFileLogger.logFileManager.sortedLogFilePaths

print("paths=\(logFilePaths)")

guard let logPath = logFilePaths.first  else { return }
        
let url = NSURL.fileURL(withPath: logPath)

let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: [])
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true) {
    ProgressHUD.dismiss()
}

Problem: logs from the extension are not saved, when reading logs there are only application logs, extension logs are not saved. I debugged the extension and checked that there are no errors (for example, if I write the wrong application group, there is an error in the console), the logs in the console are displayed normally. I don't understand what the problem is. Could you please help me with this?

0

There are 0 answers