xcode 用于生产应用程序的 Crashlytics CLS_Log 与 NSLog
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18702876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Crashlytics CLS_Log vs. NSLog for production apps
提问by Drew
No really a specific question, but I was curious if anyone has ever used CLSLog() or CLSNSLog() provided by the Crashlytics SDK?
没有真正的具体问题,但我很好奇是否有人使用过 Crashlytics SDK 提供的 CLSLog() 或 CLSNSLog()?
Up until now, my apps have been fairly small and I've just been leaving the NSLog's on all the time and even submitting the final app with them still in-tact. In hindsight, I probably should turn these off, use some other logging system, or #define a DEBUG var that will disable them upon release as I've seen people discuss in other posts.
到目前为止,我的应用程序还相当小,而且我一直都在打开 NSLog,甚至提交最终的应用程序时它们仍然完好无损。事后看来,我可能应该关闭这些,使用其他一些日志系统,或者 #define 一个 DEBUG 变量,它将在发布时禁用它们,正如我在其他帖子中看到的那样。
At any rate, just curious if anyone's used it before?
无论如何,只是好奇是否有人以前使用过它?
回答by iajheyst
The best approach to this would be to declare a preprocessor variable called DEBUG
最好的方法是声明一个名为 DEBUG 的预处理器变量
in the header, include:
在标题中,包括:
#define DEBUG 1
#define DEBUG 1
After that, for debug purposes, set DEBUG to 1, and NSLog everything.
之后,出于调试目的,将 DEBUG 设置为 1,并 NSLog 一切。
#if DEBUG==1
NSLog(@"debug mode activated, value for certain variables is: %d", i);
#endif
Before you ship the product, just change
在您运送产品之前,只需更改
#define DEBUG 0
That way, you can just leave the entire code for debugging in the app, and keep it for further development
这样,您可以将整个代码留在应用程序中进行调试,并保留以供进一步开发
CLS_LOG from Crashlytics gives you access to the Log of the app from the Crashlytics website. It also gathers information about the crash, memory warnings, how many users crashed at a certain point, etc.
Crashlytics 的 CLS_LOG 使您可以从 Crashlytics 网站访问应用程序的日志。它还收集有关崩溃、内存警告、在某个时间点崩溃的用户数量等信息。
Happy coding!
快乐编码!
edit:
编辑:
I forgot to add one thing: for the application I'm working on right now, in the prefix, we defined:
我忘了添加一件事:对于我现在正在处理的应用程序,在前缀中,我们定义了:
#define NSLog(...) CLS_LOG(__VA_ARGS__)
So, we don't ever use CLS_LOG explicitly. We only use NSLog, but all the NSLogs make it to the Crashlytics dashboard.
所以,我们从来没有明确使用 CLS_LOG。我们只使用 NSLog,但所有的 NSLog 都会进入 Crashlytics 仪表板。
回答by Mike.R
I created some .h
file with all the common constants that I need to use and added it .pch
file (in order not to make mess in it).I also imported CrashLytics
via pods (some why .pch
didn't recognised it if I included in project the usual way)
我创建了一些.h
文件,其中包含我需要使用的所有常用常量并将其添加到.pch
文件中(以免弄乱它)。我还CrashLytics
通过 pod导入(.pch
如果我以通常的方式包含在项目中,有些人为什么没有识别它)
#ifdef DEBUG
#define NSLog(...) CLS_LOG(__VA_ARGS__)
#define ServerURL @"http://TestServer"
#else
#define ServerURL @"http://RealServer"
#define NSLog(...)