iPhone 错误记录和/或报告的最佳实践 [英] Best Practices for Error Logging and/or reporting for 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:
- 在开发过程中,重置错误列表或关闭通知应该很简单.
- 在开发过程中,错误消息也应该显示在一些明显的地方,比如控制台的屏幕上
- 部署后,应礼貌地将错误发送给母舰进行分析(以便在下一次更新中修复错误)
- 在开发过程中尝试跟踪问题时打开跟踪/信息日志记录
- 关闭发布"的控制台日志记录以加快用户的操作
- 自己应该清理干净,以便在电话中做一个好公民
- 使用 GSLog 代替 NSLog
- 登录到 iPhone 上的文件
- 在 Mac 上,人们说 Apple System Logger 和 GTM Logger 是最佳选择 objective-c 日志记录最佳实践
- Jeff A 的日志记录博客条目
似乎有一个通用的工具包可以做到这一点 - 你如何处理这个问题?
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...
- PLCrashReporter.
- Quincy 位于 PLC 之上.
- Bugsense 商业崩溃报告.
- Crittercism 崩溃和错误报告(一些免费软件包,一些付费).
- 试飞 现在有一个可以捕获崩溃的 SDK(但还没有用于应用商店应用,只是开发应用).
- 与试飞一样,Hockey 旨在将临时分发与崩溃报告相结合.
- 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 在提供崩溃报告方面不可靠,我建议使用 Fabric/Crashlytics,或者像 Crittercism 或 滚动条.
- 我们发布的产品没有任何痕迹,这似乎与大多数其他 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 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.
更详细:
- 我们在许多不同的粒度级别为 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 构建设置中,选择Add User-Defined Setting"(通过单击构建配置屏幕左下角的小齿轮),然后定义一个名为 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屋!