iPhone 错误记录和/或报告的最佳实践

发布于 2024-08-10 01:06:07 字数 1686 浏览 3 评论 0原文

当我进行 Web 开发时,我使用定制的记录器来捕获致命错误并将跟踪附加到文件并向用户显示消息。我偶尔可以浏览一下文件是否发生了变化,这意味着某些用户遇到了错误,我可以深入了解他们遇到了什么。

我希望在 iPhone 上有类似的功能,但有一些注意事项:

  • 在开发过程中,重置错误列表或关闭通知应该很简单。
  • 在开发过程中,错误消息也应该显示在一些明显的地方,比如控制台的屏幕上
  • 一旦部署,错误应该礼貌地发送到母舰进行分析(以便在下次更新中修复错误)
  • 打开Trace/尝试在开发过程中追踪问题时进行信息日志
  • 记录 关闭“发布”的控制台日志记录以加快用户的速度
  • 应该自行清理,以便成为手机上的好公民

一些相关链接

似乎有一个通用工具包可以做到这一点 - 你怎么做处理这个?

[2011 年 10 月更新] 已经有了一些进展,但成熟度各不相同......

  • PLCrashReporter
  • Quincy 位于 PLC 之上。
  • Bugsense 商业崩溃报告程序。
  • Crittercism 崩溃和错误报告(一些免费包,一些付费包)。
  • Test Flight 现在有一个可以捕获崩溃的 SDK(但还不适用于应用商店应用,仅适用于开发应用)。
  • 与 Test Flight 一样,Hockey 旨在将临时分发与崩溃报告结合起来。

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.

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

Some Related Links

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

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

  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

独守阴晴ぅ圆缺 2024-08-17 01:06:07

这就是我们所做的:

更详细地说:

  • 我们在许多不同的粒度级别上定义了 NSLog 跟踪的宏。
  • 使用 Xcode 构建设置来更改跟踪级别,该级别控制将多少跟踪编译到产品中,例如,有发布和调试构建配置。
  • 如果未定义跟踪级别,则我们在模拟器中显示完整跟踪,而在真实设备上运行时则不显示跟踪。

我在下面提供了示例代码,展示了我们如何编写此代码以及输出的样子。

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

示例代码:

- (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 构建设置中,选择“添加用户定义的设置”(通过单击构建配置屏幕左下角的小齿轮),然后定义一个名为 GCC_PREPROCESSOR_DEFINITIONS 的新设置,并为其指定值 TRC_LEVEL=0代码>.

唯一的微妙之处是,如果您更改此设置,Xcode 不知道执行干净构建,因此请记住,如果您更改它,请手动执行 Clean。

Here's what we do:

  • 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 recommend using Fabric/Crashlytics, or a competitor like Crittercism or Rollbar.
  • 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.

In more detail:

  • We define macros to NSLog trace at numerous different levels of granularity.
  • Use Xcode build settings to change the trace level, which controls how much trace gets compiled into the product, e.g. there are Release and Debug build configurations.
  • If no trace level is defined then we show full trace in the Simulator, and no trace when running on a real Device.

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.

Example code:

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

Example trace output:

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:]

Our trace definitions:

#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 settings:

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.

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.

身边 2024-08-17 01:06:07

Apple 会自动为您收集用户的崩溃日志,您可以从 iTunes connect 下载它们。

如果这对您来说还不够,我不知道有工具包,但我个人不想自己推出一些东西。开发健壮的东西似乎花费了太多的精力,可能会引起隐私问题,最后,应用程序商店中有 100,000K 个应用程序,有多少用户在发现您的应用程序有错误后会再次使用您的应用程序?

Apple automatically collects crash logs from users for you, and you can download them from iTunes connect.

If that's not enough for you, I'm not aware of a toolkit but I wouldn't want to roll something on my own, personally. It seems like too much effort to develop something robust, might raise privacy concerns, and in the end, with 100,000K apps in the app store, how many users would use your application again after discovering it was buggy?

秋日私语 2024-08-17 01:06:07

您知道iPhone 版 CrashReporter 存在吗?

github 上有一个存储库,它演示了该代码。

它有一些很酷的功能,比如将堆栈跟踪映射到你的代码,并管理一些 git 特定的东西,比如版本哈希。

Do you know that CrashReporter for iPhone exists?

There is a repository on github which demos that code.

It has some cool features like maping the stack trace to your code and manages some git specific things like version hashes.

橘虞初梦 2024-08-17 01:06:07

我强烈推荐 Robbie Hanson 的 CocoaLumberJack: https://github.com/robbiehanson/CocoaLumberjack

它非常灵活,如果被滥用的话,强大甚至可能有点过分。支持不同级别的日志记录。可以通过几行代码打开文件记录,甚至可以通过网络发送记录。

I highly recommend Robbie Hanson's CocoaLumberJack: https://github.com/robbiehanson/CocoaLumberjack

It is very flexible and powerful maybe even a bit excessive if abused. Supports different levels of logging. Logging to files can be turned on with a couple of lines of code and even be sent over the network.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文