ios 如何在应用启动时阻止 Firebase 记录状态更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37311089/
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
How to stop Firebase from logging status updates when app is launched
提问by TekShock
Whenever I launch the FireBase app, it logs the status of various Firebase features. Right now this is what is being logged:
每当我启动 FireBase 应用程序时,它都会记录各种 Firebase 功能的状态。现在这是正在记录的内容:
Configuring the default app.
<FIRAnalytics/INFO> Firebase Analytics v.3200000 started
<FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see ...)
<FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist
<FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO
<FIRAnalytics/INFO> Firebase Analytics enabled
I looked through the pods and didn't find any print statements so how else would I go about stopping these from being logged overtime I run the app?
我查看了 pods 并没有找到任何打印语句,那么我还能如何阻止这些日志超时记录我运行应用程序?
回答by Ian Barber
回答by Raphael Oliveira
Add FirebaseConfiguration.shared.setLoggerLevel(.min)
before FirebaseApp.configure()
to achieve the minimum amount of logging.
添加FirebaseConfiguration.shared.setLoggerLevel(.min)
之前FirebaseApp.configure()
以实现最小日志记录量。
func setupFirebase() {
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
}
回答by Sujay U N
By default, Firebase will log info, errors, and warnings.
So u can set the logger level for which ever u need.
If you set for .Error you wil get min log only when error accours.
默认情况下,Firebase 会记录信息、错误和警告。
因此,您可以根据需要设置记录器级别。
如果您设置为 .Error 您将仅在出现错误时获得最小日志。
setLoggerLevel before FirebaseApp.configure() as shown below
FirebaseApp.configure() 之前的 setLoggerLevel 如下所示
In Swift 2.3 and Firebase 4
在 Swift 2.3 和 Firebase 4 中
FirebaseConfiguration.sharedInstance().setLoggerLevel(.Error)
FirebaseApp.configure()
In Swift 3 and Firebase 4
在 Swift 3 和 Firebase 4 中
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
回答by Jorge Casariego
In my case to hide the extra chunk of console log from Firebase I did the following:
在我的情况下,为了从 Firebase 隐藏额外的控制台日志块,我执行了以下操作:
- Navigate to Product -> Scheme -> Edit Scheme.
- Under Arguments tab in the Environment Variables section add OS_ACTIVITY_MODE = disable
- 导航到产品 -> 方案 -> 编辑方案。
- 在 Environment Variables 部分的 Arguments 选项卡下添加OS_ACTIVITY_MODE = disable
- Just in case you will need that, just simply uncheck the box.
- Disabling OS_ACTIVITY_MODEsometimes will disable logs for all exceptions as well
- 以防万一您需要它,只需取消选中该框即可。
- 禁用OS_ACTIVITY_MODE有时也会禁用所有异常的日志
Edit 1: As @jesus-adolfo-rodriguez said, this is related to Xcode. So, if you don't want OSLog on the Xcode console, put OS_ACTIVITY_MODE Environment variable to “disable” in your scheme.
编辑 1:正如@jesus-adolfo-rodriguez 所说,这与 Xcode 相关。因此,如果您不想在 Xcode 控制台上使用 OSLog,请将 OS_ACTIVITY_MODE 环境变量置于您的方案中“禁用”。
Edit 2:
编辑2:
FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
More details in the FIRConfiguration implementation here
此处FIRConfiguration 实现中的更多详细信息
Edit 3: 2019
编辑 3:2019
According to this issue: https://github.com/firebase/firebase-ios-sdk/issues/2774#issuecomment-482780714
根据这个问题:https: //github.com/firebase/firebase-ios-sdk/issues/2774#issuecomment-482780714
Adding -FIRDebugDisabledargument and cleaning the project did the trick.
添加-FIRDebugDisabled参数并清理项目就行了。
The logging system in Firebase
The logging system has two modes: default mode and debug mode. In default mode, only logs with log level Notice, Warning and Error will be sent to device. In debug mode, all logs will be sent to device. The log levels that Firebase uses are consistent with the ASL log levels.
Enable debug mode by passing the -FIRDebugEnabled argument to the application. You can add this argument in the application's Xcode scheme. When debug mode is enabled via -FIRDebugEnabled, further executions of the application will also be in debug mode. In order to return to default mode, you must explicitly disable the debug mode with the application argument -FIRDebugDisabled.
It is also possible to change the default logging level in code by calling setLoggerLevel: on the FIRConfiguration interface.
日志系统有两种模式:默认模式和调试模式。在默认模式下,只有日志级别为 Notice、Warning 和 Error 的日志才会发送到设备。在调试模式下,所有日志都将发送到设备。Firebase 使用的日志级别与 ASL 日志级别一致。
通过将 -FIRDebugEnabled 参数传递给应用程序来启用调试模式。您可以在应用程序的 Xcode 方案中添加此参数。当通过 -FIRDebugEnabled 启用调试模式时,应用程序的进一步执行也将处于调试模式。为了返回默认模式,您必须使用应用程序参数-FIRDebugDisabled显式禁用调试模式。
还可以通过在 FIRConfiguration 接口上调用 setLoggerLevel: 来更改代码中的默认日志记录级别。
回答by Chatar Veer Suthar
FIRConfiguration.sharedInstance().setLoggerLevel(.min)
FIRApp.configure()
In Swift 4
在斯威夫特 4
回答by Ond?ej ?ev?ík
Swift 4 Firebase 4.10
斯威夫特 4 Firebase 4.10
Set logger level in your AppDelegate.swift
在 AppDelegate.swift 中设置记录器级别
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
Here is full code:
这是完整的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
return true
}
回答by djabi
By default Firebase Analytics will only log 4 INFO lines in production + errors/warnings. That should be very little output if things work correctly. Adding -noFIRAnalyticsDebugEnabled will only disable DEBUG level logs and ERROR/WARN are always logged. If you see any warnings or errors you probably need to do something to resolve the cause. Some things will likely not work correctly if warnings/errors are logged. App that is correctly setup should not log errors/warnings.
默认情况下,Firebase Analytics 只会在生产+错误/警告中记录 4 个 INFO 行。如果一切正常,那应该是很少的输出。添加 -noFIRAnalyticsDebugEnabled 只会禁用调试级别的日志,并且始终记录错误/警告。如果您看到任何警告或错误,您可能需要采取措施解决问题。如果记录警告/错误,有些事情可能无法正常工作。正确设置的应用程序不应记录错误/警告。
Messages tagged with FIRInstanceID/* are logged by Firebase Notification and errors/warnings are always logged.
Firebase 通知会记录标记为 FIRInstanceID/* 的消息,并且始终会记录错误/警告。
回答by adbitx
As djabi said, you cannot disable those logs if they are INFO, WARNING or ERROR.
正如 djabi 所说,如果这些日志是 INFO、WARNING 或 ERROR,则不能禁用它们。
I want to add to Nitin Gohel's answer since I can't comment: The flag FirebaseAppDelegateProxyEnabledis not for disabling logs. If you turn it off, you will lose the auto campaigntracking and you will need to add the methods from FIRAnalytics(AppDelegate) to handle URL and user activity yourself.
我想添加到 Nitin Gohel 的回答中,因为我无法发表评论:FirebaseAppDelegateProxyEnabled标志不是用于禁用日志。如果您将其关闭,您将失去自动活动跟踪功能,您需要添加来自 FIRAnalytics(AppDelegate) 的方法来自行处理 URL 和用户活动。
回答by onmyway133
To add to Alex' answer, from https://firebase.google.com/docs/cloud-messaging/ios/client
添加到亚历克斯的答案,来自https://firebase.google.com/docs/cloud-messaging/ios/client
FirebaseAppDelegateProxyEnabled
is for swizzling your app delegate 's methods
FirebaseAppDelegateProxyEnabled
用于调整您的应用程序委托的方法
The FCM API performs method swizzling in two key areas: mapping your APNs token to the FCM registration token and capturing analytics data during downstream message callback handling. Developers who prefer not to use swizzling can disable it by adding the flag FirebaseAppDelegateProxyEnabledin the app's Info.plist file and setting it to NO (boolean value). Relevant areas of the guides provide code examples, both with and without method swizzling enabled.
FCM API 在两个关键领域执行方法 swizzling:将您的 APNs 令牌映射到 FCM 注册令牌并在下游消息回调处理期间捕获分析数据。不喜欢使用 swizzling 的开发人员可以通过在应用程序的 Info.plist 文件中添加标志FirebaseAppDelegateProxyEnabled并将其设置为 NO(布尔值)来禁用它。指南的相关区域提供了启用和不启用方法调配的代码示例。
回答by rgkobashi
I think there is a big and a very important confusion going on.
我认为有一个很大且非常重要的混乱正在发生。
By using -FIRDebugDisabled
it will disable debug modewhich then your measurements will be affected during testing and development.
通过使用-FIRDebugDisabled
它将禁用调试模式,然后您的测量将在测试和开发过程中受到影响。
To reduce the logs:
要减少日志:
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
However there is a bugon versions 6.18 and 6.20.
但是,版本 6.18 和 6.20 上存在一个错误。
As workaround you can use -noFIRAnalyticsDebugEnabled
which is a different thing, this one does not disableyour debug mode.
作为解决方法,您可以使用-noFIRAnalyticsDebugEnabled
不同的方法,此方法不会禁用您的调试模式。