remirobert / Dotzu

:iphone::eyes: In-App iOS Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
MIT License
1.8k stars 141 forks source link

Slow printing to console #41

Open mkeremkeskin opened 6 years ago

mkeremkeskin commented 6 years ago

Hey there,

I'm logging a lot of stuff like arrays etc. By using using Dotzu's print() (overrides standart version) method or Dotzu's Logger class methods, I observed that logs appearing on console really slow comparing to standard print() method.

I want to continue using Dotzu beacuse it's nice to see the logs on the app for our QA team. But this slow logging really affects my development routine. Do you have an idea what is the problem?

Btw I'm using the latest release of Dotzu and XCode 9. For earlier release of XCode 8 the was no problem. But I was facing the issue on latest XCode 8 version.

Thanks.

johndpope commented 6 years ago

the problem is nsarchive - it needs to be ripped out. @remirobert - lets fix this. it should be a couple of lines to switch out let dataArchive = NSKeyedArchiver.archivedData(withRootObject: logs)

and use a different storage provider my vote is to use https://github.com/pinterest/PINCache


class StoreManager<T> where T: NSCoding {

    private let store: StoreManagerType

    init(store: StoreManagerType) {
        self.store = store
    }

    private func archiveLogs(logs: [T]) {
        let dataArchive = NSKeyedArchiver.archivedData(withRootObject: logs)
        UserDefaults.standard.set(dataArchive, forKey: store.rawValue)
        UserDefaults.standard.synchronize()
    }

    func add(log: T) {
        var logs = self.logs()
        logs.append(log)
        archiveLogs(logs: logs)
    }

    func save(logs: [T]) {
        archiveLogs(logs: logs)
    }

    func logs() -> [T] {
        guard let data = UserDefaults.standard.object(forKey: store.rawValue) as? NSData else {return []}
        do {
            let dataArchive = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data)
            return dataArchive as? [T] ?? []
        } catch {
            return []
        }
    }

    func reset() {
        UserDefaults.standard.removeObject(forKey: store.rawValue)
        UserDefaults.standard.synchronize()
    }
}

https://github.com/remirobert/Dotzu/issues/29

https://github.com/remirobert/Dotzu-Objective-c/issues/4

screen shot 2017-11-26 at 10 42 42 am

johndpope commented 6 years ago

@mkeremkeskin - you can use this https://github.com/PTEz/LumberjackConsole