pj4533 / yourgoal

Swift implementation of BabyAGI
MIT License
50 stars 8 forks source link

Add unified logging #19

Open pj4533 opened 1 year ago

pj4533 commented 1 year ago

Replace my current debug logging with the proper API

https://developer.apple.com/documentation/os/logging

pj4533 commented 1 year ago

Support easy debugging of json responses too like this:

                do {
                    // Attempt to deserialize the Data object to a JSON object
                    let jsonObject = try JSONSerialization.jsonObject(with: data, options: [])

                    // Convert the JSON object to a pretty-printed string
                    let decodedJsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: [.prettyPrinted])
                    DebugLog.shared.log(String(data: decodedJsonData, encoding: .utf8) ?? "")
                } catch {
                    print("Error converting Data to JSON decoded string: \(error)")
                }