子类化CocoaLumberJack(Subclassing CocoaLumberJack)

编程入门 行业动态 更新时间:2024-10-27 15:26:36
子类化CocoaLumberJack(Subclassing CocoaLumberJack)

我的应用程序中有一堆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.

更多推荐

本文发布于:2023-07-30 06:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子类   CocoaLumberJack   Subclassing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!