Where is Logfile stored using cocoaLumberjack

前端 未结 9 1037
不知归路
不知归路 2020-12-22 18:07

I am Using cocoaLumberjack logging framework for iOS logging. For storing logs in a file I used this code.

DDFileLogger* fileLogger = [[DDFileLogger alloc] i         


        
9条回答
  •  半阙折子戏
    2020-12-22 18:37

    I had to rewrite it a little to be compatible with Swift 4...

    var logFileDataArray: [Data] {
        let logFilePaths = delegate.fileLogger.logFileManager.sortedLogFilePaths
        var logFileDataArray = [Data]()
        for logFilePath in logFilePaths {
            let fileURL = URL(fileURLWithPath: logFilePath)
            if let logFileData =
                try? Data(contentsOf: fileURL, options: Data.ReadingOptions.mappedIfSafe) {
                logFileDataArray.insert(logFileData, at: 0)
            }
        }
        return logFileDataArray
    }
    
    func sendApplicationLog(text: String) {
        if MFMailComposeViewController.canSendMail() {
            let controller = MFMailComposeViewController()
            controller.mailComposeDelegate = self
            controller.setToRecipients(["dohan.rene@gmail.com"])
            controller.setSubject("Log of motorkari iOS")
            controller.setMessageBody(text, isHTML: false)
            var attachmentData = Data()
            for logFileData in logFileDataArray { attachmentData.append(logFileData) }
            controller.addAttachmentData(attachmentData, mimeType: "text/plain",
                                        fileName: "motorkari_ios_application.log")
            present(controller, animated: true, completion: nil)
        } else {
            showMessage("Log cannot be send !")
        }
    }
    

提交回复
热议问题