简体   繁体   English

如何在应用程序启动时阻止 Firebase 记录状态更新

[英]How to stop Firebase from logging status updates when app is launched

Whenever I launch the FireBase app, it logs the status of various Firebase features.每当我启动 FireBase 应用程序时,它都会记录各种 Firebase 功能的状态。 Right now this is what is being logged:现在这是正在记录的内容:

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?我查看了 pod 并没有找到任何打印语句,所以我 go 如何阻止这些在我运行应用程序时被超时记录?

You can disable the debug logging with the flag -FIRDebugDisabled .您可以使用标志-FIRDebugDisabled禁用调试日志记录。

You can add it to your scheme :您可以将其添加到您的方案中

  1. Select Scheme toolbar选择方案工具栏
  2. Edit Scheme编辑方案
  3. Select Run选择运行
  4. Click Arguments and add -FIRDebugDisabled单击参数并添加-FIRDebugDisabled

Add FirebaseConfiguration.shared.setLoggerLevel(.min) before FirebaseApp.configure() to achieve the minimum amount of logging.FirebaseApp.configure() FirebaseConfiguration.shared.setLoggerLevel(.min)之前添加FirebaseConfiguration.shared.setLoggerLevel(.min)以实现最小日志记录量。

func setupFirebase() {
  FirebaseConfiguration.shared.setLoggerLevel(.min)
  FirebaseApp.configure()
}

By default, Firebase will log info, errors, and warnings.默认情况下,Firebase 会记录信息、错误和警告。
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.如果您设置为 .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()

In my case to hide the extra chunk of console log from Firebase I did the following:在我的情况下,为了从 Firebase 隐藏额外的控制台日志块,我执行了以下操作:

  1. Navigate to Product -> Scheme -> Edit Scheme.导航到产品 -> 方案 -> 编辑方案。
  2. 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_MODE sometimes will disable logs for all exceptions as well禁用OS_ACTIVITY_MODE有时也会禁用所有异常的日志

Edit 1 : As @jesus-adolfo-rodriguez said, this is related to Xcode.编辑 1 :正如@jesus-adolfo-rodriguez 所说,这与 Xcode 相关。 So, if you don't want OSLog on the Xcode console, put OS_ACTIVITY_MODE Environment variable to “disable” in your scheme.因此,如果您不想在 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 -FIRDebugDisabled argument and cleaning the project did the trick.添加-FIRDebugDisabled参数并清理项目就行了。

The logging system in Firebase 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.在默认模式下,只有日志级别为 Notice、Warning 和 Error 的日志才会发送到设备。 In debug mode, all logs will be sent to device.在调试模式下,所有日志都将发送到设备。 The log levels that Firebase uses are consistent with the ASL log levels. Firebase 使用的日志级别与 ASL 日志级别一致。

Enable debug mode by passing the -FIRDebugEnabled argument to the application.通过将 -FIRDebugEnabled 参数传递给应用程序来启用调试模式。 You can add this argument in the application's Xcode scheme.您可以在应用程序的 Xcode 方案中添加此参数。 When debug mode is enabled via -FIRDebugEnabled, further executions of the application will also be in debug mode.当通过 -FIRDebugEnabled 启用调试模式时,应用程序的进一步执行也将处于调试模式。 In order to return to default mode, you must explicitly disable the debug mode with the application argument -FIRDebugDisabled .为了返回默认模式,您必须使用应用程序参数-FIRDebugDisabled显式禁用调试模式。

It is also possible to change the default logging level in code by calling setLoggerLevel: on the FIRConfiguration interface.还可以通过在 FIRConfiguration 接口上调用 setLoggerLevel: 来更改代码中的默认日志记录级别。

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
}
FIRConfiguration.sharedInstance().setLoggerLevel(.min)
FIRApp.configure()

In Swift 4在斯威夫特 4

By default Firebase Analytics will only log 4 INFO lines in production + errors/warnings.默认情况下,Firebase Analytics 只会在生产+错误/警告中记录 4 个 INFO 行。 That should be very little output if things work correctly.如果一切正常,那应该是很少的输出。 Adding -noFIRAnalyticsDebugEnabled will only disable DEBUG level logs and ERROR/WARN are always logged.添加 -noFIRAnalyticsDebugEnabled 只会禁用调试级别的日志,并且始终记录错误/警告。 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.正确设置的应用程序不应记录错误/警告。

Messages tagged with FIRInstanceID/* are logged by Firebase Notification and errors/warnings are always logged. Firebase 通知会记录标记为 FIRInstanceID/* 的消息,并且始终会记录错误/警告。

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 FirebaseAppDelegateProxyEnabled is not for disabling logs.我想添加到 Nitin Gohel 的回答中,因为我无法发表评论: FirebaseAppDelegateProxyEnabled标志不是用于禁用日志。 If you turn it off, you will lose the auto campaign tracking and you will need to add the methods from FIRAnalytics(AppDelegate) to handle URL and user activity yourself.如果您将其关闭,您将失去自动活动跟踪功能,您需要添加来自 FIRAnalytics(AppDelegate) 的方法来自己处理 URL 和用户活动。

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. FCM API 在两个关键领域执行方法调整:将您的 APNs 令牌映射到 FCM 注册令牌并在下游消息回调处理期间捕获分析数据。 Developers who prefer not to use swizzling can disable it by adding the flag FirebaseAppDelegateProxyEnabled in the app's Info.plist file and setting it to NO (boolean value).不喜欢使用 swizzling 的开发人员可以通过在应用程序的 Info.plist 文件中添加标志FirebaseAppDelegateProxyEnabled并将其设置为 NO(布尔值)来禁用它。 Relevant areas of the guides provide code examples, both with and without method swizzling enabled.指南的相关区域提供了启用和不启用方法调配的代码示例。

I think there is a big and a very important confusion going on.我认为有一个很大且非常重要的混乱正在发生。

By using -FIRDebugDisabled it will disable debug mode which then your measurements will be affected during testing and development .通过使用-FIRDebugDisabled它将禁用调试模式,然后您的测量将在测试和开发过程中受到影响

Currently there is no way to enable debug mode and disable logs at the same time.目前无法同时启用调试模式和禁用日志。 So the FirebaseConfiguration.shared.setLoggerLevel(.min) will work basically on not debug mode only.所以FirebaseConfiguration.shared.setLoggerLevel(.min)基本上只能在非调试模式下工作。

As workaround you can use -noFIRAnalyticsDebugEnabled which is only for Xcode console logging , this one does not disable your debug mode.作为解决方法,您可以使用仅用于Xcode 控制台日志记录的-noFIRAnalyticsDebugEnabled ,这不会禁用您的调试模式。

If you want the clean and necessary logs in console, just set your scheme like this.如果您想在控制台中获得干净且必要的日志,只需像这样设置您的方案。 Open the "Edit Scheme" and select "Arguments".打开“编辑方案”和 select “参数”。

  • -FIRAnalyticsDebugEnabled (don't forget "-") -FIRAnalyticsDebugEnabled(不要忘记“-”)
  • OS_ACTIVITY_MODE = disable OS_ACTIVITY_MODE = 禁用

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何阻止 firebase 函数传播触发器 - How to stop firebase functions from propagating triggers 如何从节点 js 应用程序向客户端发送实时更新 - how to send realtime updates to client from node js app Firebase app在后台时如何处理通知 - How to handle notification when app in background in Firebase firebase - 限制用户登录 14 天 - firebase - restrict user from logging in for 14 days 如何从 Android 应用程序中删除 Firebase 用户? - How to delete a Firebase user from Android App? 如何防止用户删除Firebase App - How to prevent User from deleting Firebase App 当收到来自 Firebase 的通知并且我打开了应用程序时,我该如何处理? - How can I handle a notification from Firebase when it arrives and I have the app open? Firebase Firestore 的 snapshots() 是如何制作的,以及它如何使用 flutter 应用程序中的 stream 监听数据库更新 - How the Firebase Firestore's snapshots() is made and how it can listen to the database updates with a stream inside the flutter app 当用户更新密码时,如何捕获 Firebase Auth 返回的特定错误? - How do I catch specific error returned by Firebase Auth, when user updates their password? 在 Android 上登录 Facebook/Firebase 时出错 - Error When Logging on Facebook/Firebase on Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM