You can download log files from a connected device or send them directly from the application. Both approaches are described below.
Send log files from the application via email to Swift
Write this in a class where you have a link to DDFileLogger. I would put this in a custom registrar class, for example. MyLogger.swift
var ddFileLogger: DDFileLogger! var logFileDataArray: [NSData] { get { let logFilePaths = ddFileLogger.logFileManager.sortedLogFilePaths() as! [String] var logFileDataArray = [NSData]() for logFilePath in logFilePaths { let fileURL = NSURL(fileURLWithPath: logFilePath) if let logFileData = try? NSData(contentsOfURL: fileURL, options: NSDataReadingOptions.DataReadingMappedIfSafe) { // Insert at front to reverse the order, so that oldest logs appear first. logFileDataArray.insert(logFileData, atIndex: 0) } } return logFileDataArray } }
Then, when the user clicks a button to indicate that they want to send logs,
// Required by MFMailComposeViewController import MessageUI @IBAction func writeEmailTapped(sender: AnyObject) { if MFMailComposeViewController.canSendMail() { let composeVC = MFMailComposeViewController() composeVC.mailComposeDelegate = self // Configure the fields of the interface. composeVC.setToRecipients(["your-email@company.com"]) composeVC.setSubject("Feedback for app") composeVC.setMessageBody("", isHTML: false) let attachmentData = NSMutableData() for logFileData in MyLogger.sharedInstance.logFileDataArray { attachmentData.appendData(logFileData) } composeVC.addAttachmentData(attachmentData, mimeType: "text/plain", fileName: "diagnostic.log") self.presentViewController(composeVC, animated: true, completion: nil) } else { // Tell user about not able to send email directly. } }
This creates an email popup with an attachment file named diagnostic.log , which is all the log files combined together.
Special thanks are almost a translation of Swift from the Objective-C version given by another answer.
Get the log file from the device directly, via a USB cable
If you want to get the log files created by your application on the device,
- Connect your device to Mac.
- In Xcode, go to Window -> Devices
- In the upper left corner of the list of devices, click on the connected device.
- In the main panel, under the "Installed applications" section, click the application in which you launched CocoaLumberjack.
- At the bottom of the Installed Applications list, click the gear icon and then Download Container.
- In Finder, right-click (show menu) in the saved .xcappdata file and select "Show Package Contents"
- Log files are saved in
/AppData/Library/Caches/Logs/
Pausing the vote would be nice if it were useful to you!
Daniel Dec 22 '12 at 5:33 2012-12-22 05:33
source share