我的应用程序中有一堆DDLogError语句。 我开始与朋友和家人一起测试应用程序。 每当其中一个测试应用程序遇到错误时,我希望能够自动返回日志。
Brute Force方法是在每个DDLogError语句下面添加一些DDLogError ,用于跟踪应用程序出错的事实并定期在后台上传这些用户的日志。
现在我已经将100多个这些语句分散在我的代码中,我宁愿只是全局更改DDLogError ,这样它就不会打印我在格式字符串中给出的内容,而且还会更新一个说明应用程序遇到错误情况的属性。
什么是最好的方法呢? 子类CocoaLumberJack类然后重写DDLogError方法?
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?
最满意答案
我通过使用https://github.com/CocoaLumberjack/CocoaLumberjack/blob/master/Documentation/CustomFormatters.md中描述的CustomFormatter解决了这个问题。
基本上,我将fileLogger与自定义格式化程序相关联。 在自定义格式化程序中,每当调用DDLogError时,我都会执行所有额外步骤,例如跟踪发生错误以及在WiFi和后台上需要上载日志,添加一些自定义字符串以简化过滤等。
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.
更多推荐
发布评论