iPhone的错误日志记录和/或报告的最佳做法 [英] Best Practices for Error Logging and/or reporting for iPhone

查看:344
本文介绍了iPhone的错误日志记录和/或报告的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进行Web开发时,我使用一个自定义记录器来捕获致命错误,并将跟踪追加到文件中,并向用户显示一条消息。我偶尔会看到文件是否发生变化,这意味着有些用户遇到错误,我可以深入了解他们遇到的情况。

When I do web development, I use a custom made logger that catches fatal errors and appends a trace to a file and displays a message to the user. I can occasionally glance to see if the file changed, which means, some user encountered an error and I can dig in to see what they encountered.

我想在iphone上看到类似的东西,有一些注意事项:

I'd like something similar on the iphone, with some caveats:


  • 在开发中,重置错误列表或关闭通知应该是微不足道的。

  • 在开发过程中,错误消息也应该显示在一些明显的地方,如屏幕上在控制台中

  • 部署完成后,应该礼貌地将错误发送给母亲进行分析(下次更新时出现错误修复)

  • 打开

  • 关闭发布的控制台日志记录以加快用户的使用情况

  • 应该清理自己,以便在电话中成为一个好的公民

  • While developing, it should be trivial to reset the list of errors or turn off notification.
  • While developing, the error messages should also show up in some obvious place, like on the screen on in the console
  • Once deployed, errors should politely be sent to the mothership for analysis (for a bug fix in the next update)
  • Turn on Trace/Info logging when trying to track down a problem during development
  • Turn off console logging for 'Release' to speed up things for the user
  • Should clean-up after itself so as to be a good citizen on the phone
  • Using GSLog for instead of NSLog
  • logging to a file on the iphone
  • On the Mac, people say Apple System Logger and GTM Logger are the way to go objective-c logging best practices
  • Jeff A's Blog entry on logging

似乎有一个常见的工具包来做这个 - 你如何处理?

It seem like there would be a common toolkit to do this - how do you handle this?

[2011年10月更新]
有一些发展,不同的成熟度...

[Update Oct 2011] There have been some developments, of varying maturity...


  • < a href =https://www.plcrashreporter.org =nofollow noreferrer> PLCrashReporter 。

  • Quincy 位于PLC的顶部。

  • Bugsense 商业崩盘记者。

  • Crittercism 崩溃和错误报告(一些免费软件包,一些付费)。

  • 测试航班现在有一个SDK可以捕捉崩溃(但还没有应用程序商店应用程序,只是开发应用程序)。

  • 像测试飞行一样,曲棍球旨在结合广告

  • PLCrashReporter.
  • Quincy sits on top of PLC.
  • Bugsense commercial crash reporter.
  • Crittercism crash and error reporting (some free packages, some paid).
  • Test flight now has an SDK that catches crashes (but not yet for app store apps, just dev apps).
  • Like Test Flight, Hockey aims to combine ad hoc distribution with crash reporting.

推荐答案

这是我们的工作:


  • 让iPhone通过现有的App Store机制更新:发现iTunes Connect在提供崩溃报告时不可靠,我开始使用 Crittercism Rollbar 在我的一些应用程序。它做得好,有一个免费的计划。

  • 我们发布的产品没有痕迹,这似乎与大多数其他iPhone应用程序一致。

  • 如果报告错误,我们使用跟踪构建再现它。

  • Let the iPhone handle its own crash dumps through the existing App Store mechanisms. Update: having found iTunes Connect to be unreliable at providing crash reports, I've started using Crittercism and Rollbar in some of my apps. It does the job well, and has a free plan.
  • Our released product has no trace in, this seems to be consistent with what most other iPhone apps do.
  • If a bug is reported then we reproduce it using a traced build.

更详细地:


  • 我们在多个不同的粒度级别下将宏定义到NSLog跟踪。

  • 使用Xcode构建设置更改跟踪级别,该级别控制多少跟踪被编译到产品中,例如有发布和调试构建配置。

  • 如果没有定义跟踪级别,那么我们在模拟器中显示完整的跟踪,并且在真实设备上运行时没有跟踪。

我已经包括了下面的示例代码,显示了我们如何编写它,以及输出的内容。

I've included example code below showing how we've written this, and what the output looks like.

我们定义了多个不同的跟踪级别,因此开发人员可以识别出哪些跟踪行很重要,并且可以过滤掉较低级别的详细信息。

We define multiple different trace levels so developers can identify which lines of trace are important, and can filter out lower level detail if they want to.

示例代码

- (void)myMethod:(NSObject *)xiObj
{
  TRC_ENTRY;
  TRC_DBG(@"Boring low level stuff");
  TRC_NRM(@"Higher level trace for more important info");
  TRC_ALT(@"Really important trace, something bad is happening");
  TRC_ERR(@"Error, this indicates a coding bug or unexpected condition");
  TRC_EXIT;
}

跟踪输出示例

2009-09-11 14:22:48.051 MyApp[3122:207] ENTRY:+[MyClass myMethod:]
2009-09-11 14:22:48.063 MyApp[3122:207] DEBUG:+[MyClass myMethod:]:Boring low level stuff
2009-09-11 14:22:48.063 MyApp[3122:207] NORMAL:+[MyClass myMethod:]:Higher level trace for more important info
2009-09-11 14:22:48.063 MyApp[3122:207] ALERT:+[MyClass myMethod:]:Really important trace, something bad is happening
2009-09-11 14:22:48.063 MyApp[3122:207] ERROR:+[MyClass myMethod:]:Error, this indicates a coding bug or unexpected condition
2009-09-11 14:22:48.073 MyApp[3122:207] EXIT:+[MyClass myMethod:]

定义:

#ifndef TRC_LEVEL
#if TARGET_IPHONE_SIMULATOR != 0
#define TRC_LEVEL 0
#else
#define TRC_LEVEL 5
#endif
#endif

/*****************************************************************************/
/* Entry/exit trace macros                                                   */
/*****************************************************************************/
#if TRC_LEVEL == 0
#define TRC_ENTRY    NSLog(@"ENTRY: %s:%d:", __PRETTY_FUNCTION__,__LINE__);
#define TRC_EXIT     NSLog(@"EXIT:  %s:%d:", __PRETTY_FUNCTION__,__LINE__);
#else
#define TRC_ENTRY
#define TRC_EXIT
#endif

/*****************************************************************************/
/* Debug trace macros                                                        */
/*****************************************************************************/
#if (TRC_LEVEL <= 1)
#define TRC_DBG(A, ...) NSLog(@"DEBUG: %s:%d:%@", __PRETTY_FUNCTION__,__LINE__,[NSString stringWithFormat:A, ## __VA_ARGS__]);
#else
#define TRC_DBG(A, ...)
#endif

#if (TRC_LEVEL <= 2)
#define TRC_NRM(A, ...) NSLog(@"NORMAL:%s:%d:%@", __PRETTY_FUNCTION__,__LINE__,[NSString stringWithFormat:A, ## __VA_ARGS__]);
#else
#define TRC_NRM(A, ...)
#endif

#if (TRC_LEVEL <= 3)
#define TRC_ALT(A, ...) NSLog(@"ALERT: %s:%d:%@", __PRETTY_FUNCTION__,__LINE__,[NSString stringWithFormat:A, ## __VA_ARGS__]);
#else
#define TRC_ALT(A, ...)
#endif

#if (TRC_LEVEL <= 4)
#define TRC_ERR(A, ...) NSLog(@"ERROR: %s:%d:%@", __PRETTY_FUNCTION__,__LINE__,[NSString stringWithFormat:A, ## __VA_ARGS__]);
#else
#define TRC_ERR(A, ...)
#endif

Xcode设置

在Xcode构建设置中,选择添加用户定义的设置(点击小cog在构建配置屏幕的左下角),然后定义一个名为 GCC_PREPROCESSOR_DEFINITIONS 的新设置,并给它值 TRC_LEVEL = 0

In Xcode build settings, choose "Add User-Defined Setting" (by clicking on the little cog at the bottom left of the build configuration screen), then define a new setting called GCC_PREPROCESSOR_DEFINITIONS and give it the value TRC_LEVEL=0.

唯一的微妙之处在于,如果您更改此设置,则Xcode不会做一个干净的构建,因此,如果您更改它,请记住手动执行清除 。

The only subtlety is that Xcode doesn't know to do a clean build if you change this setting, so remember to manually do a Clean if you change it.

这篇关于iPhone的错误日志记录和/或报告的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆