I have a bunch of DDLogError
statements in my app. I am starting to test the app with friends and family. Whenever one of these test apps hits an error, I want to be able to get back the logs automatically.
Brute Force way is to add something below each DDLogError
statement, that keeps track of the fact that the app hit an error and periodically upload logs from such users in the background.
Now that I have 100s of these statements scattered all over my code, I would prefer to just change DDLogError
globally so that it not prints what I give in the format string but also updates a property that says the app hit an error condition.
Whats the best way to do this? Subclass CocoaLumberJack class and then override the DDLogError
method?
I solved the problem by using a CustomFormatter as described in https://github.com/CocoaLumberjack/CocoaLumberjack/blob/master/Documentation/CustomFormatters.md
Basically, I associated my fileLogger with a custom formatter. In The custom formatter, whenever an DDLogError is called, I do all my extra steps like keeping track that error occurred and logs needs to be uploaded when on WiFi and in background, adding some custom string to make filtering easy etc.