1

I have a simple Mac OS menu bar app (top right). It performs a couple basic server calls and organizes data. For reasons too long to explain, I can't build/test the app on the computer directly so what I've been doing is compiling and archiving on my development machine and then transferring the app over to be run on the server computer.

For debugging purposes, I have a function that will save my print statements to a text file along with a timestamp.

    let fileName = "errorLogs"
let DocumentDirURL = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let fileURL = DocumentDirURL.appendingPathComponent(fileName).appendingPathExtension("txt")
var readString = ""
do {
    // Read the file contents
    readString = try String(contentsOf: fileURL)
} catch let error as NSError {
    print("Failed reading from URL: \(fileURL), Error: " + error.localizedDescription)
}
let modifiedString = "\(readString)\n\(Date()): \(text)"
do {
// Write to the file
try modifiedString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8)
} catch let error as NSError {
    print("Failed writing to URL: \(fileURL), Error: " + error.localizedDescription)
}

It works pretty well for runtime issues, however the problem is when the app crashes all together. I'd like to get an output like I would if I was testing the app in an Xcode simulator environment.

So my question is this. Is it possible to have a stack trace type debug log output to a text file so that I can get a better idea of where the app is crashing?

3
  • 1
    Would suggest using XCGLogger where you can write logs directly to a specific path. github.com/DaveWoodCom/XCGLogger Commented Jul 20, 2017 at 16:06
  • 1
    I would run Xcode on the on the machine that you are using to test the app. Or use something like fabric.io and install the crash Crashlytics or some other type of Crashlytics add-on. Commented Jul 20, 2017 at 16:18
  • MwcsMac: I would do that however the machine is in an ultra secure environment which doesn't allow Xcode to run. I'll check out the XCGLogger thing though, that looks like it might do the trick. Thanks! Commented Jul 21, 2017 at 15:21

1 Answer 1

1

I actually ended up going with @MwcsMac's solution. I installed Xcode to the machine outside of the network then brought it back into the network where I'm able to run the app and test how I need. I'm not able to update Xcode however I don't really need to.

My error log solution above tips me off to problems and then opening and running the app through Xcode gives me the specifics. Thanks everyone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.