Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Slow printing to console #41

Open
mkeremkeskin opened this issue Sep 27, 2017 · 2 comments
Open

Slow printing to console #41

mkeremkeskin opened this issue Sep 27, 2017 · 2 comments

Comments

@mkeremkeskin
Copy link

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
Copy link

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()
    }
}

#29

remirobert/Dotzu-Objective-c#4

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

@johndpope
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants