1

I'm trying to read the logs of my app through my code, I did find this question that helped me get started and managed to read the logs issued by NSLog, my code is

func systemLogs() -> [String] {
    let q = asl_new(UInt32(ASL_TYPE_QUERY))
    let r = asl_search(nil, q)
    var m = asl_next(r)
    var log = [String]()
    while m != nil {
        let message = String.fromCString(asl_get(m, ASL_KEY_MSG))
        let timeStamp = String.fromCString(asl_get(m, "CFLog Local Time"))
        if let msg = message{
            log.append("\(timeStamp!) | \(msg)")
        }
        m = asl_next(r)
    }
    asl_release(r)
    return log
}

Now this only works for logs printed with NSLog, it doesn't capture anything with swift's print().

Is there a way to also retrieve the messages printed by print() ?

Jimmar
  • 4,194
  • 2
  • 28
  • 43

0 Answers0