[英]How to stop Firebase from logging status updates when app is launched
每當我啟動 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
我查看了 pod 並沒有找到任何打印語句,所以我 go 如何阻止這些在我運行應用程序時被超時記錄?
在FirebaseApp.configure()
FirebaseConfiguration.shared.setLoggerLevel(.min)
之前添加FirebaseConfiguration.shared.setLoggerLevel(.min)
以實現最小日志記錄量。
func setupFirebase() {
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
}
默認情況下,Firebase 會記錄信息、錯誤和警告。
因此,您可以根據需要設置記錄器級別。
如果您設置為 .Error 您將僅在出現錯誤時獲得最小日志。
FirebaseApp.configure() 之前的 setLoggerLevel 如下所示
在 Swift 2.3 和 Firebase 4 中
FirebaseConfiguration.sharedInstance().setLoggerLevel(.Error)
FirebaseApp.configure()
在 Swift 3 和 Firebase 4 中
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
在我的情況下,為了從 Firebase 隱藏額外的控制台日志塊,我執行了以下操作:
編輯 1 :正如@jesus-adolfo-rodriguez 所說,這與 Xcode 相關。 因此,如果您不想在 Xcode 控制台上使用 OSLog,請將 OS_ACTIVITY_MODE 環境變量置於您的方案中“禁用”。
編輯2:
FirebaseConfiguration.shared.setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
此處FIRConfiguration 實現中的更多詳細信息
編輯 3:2019
根據這個問題: https : //github.com/firebase/firebase-ios-sdk/issues/2774#issuecomment-482780714
添加-FIRDebugDisabled參數並清理項目就行了。
日志系統有兩種模式:默認模式和調試模式。 在默認模式下,只有日志級別為 Notice、Warning 和 Error 的日志才會發送到設備。 在調試模式下,所有日志都將發送到設備。 Firebase 使用的日志級別與 ASL 日志級別一致。
通過將 -FIRDebugEnabled 參數傳遞給應用程序來啟用調試模式。 您可以在應用程序的 Xcode 方案中添加此參數。 當通過 -FIRDebugEnabled 啟用調試模式時,應用程序的進一步執行也將處於調試模式。 為了返回默認模式,您必須使用應用程序參數-FIRDebugDisabled顯式禁用調試模式。
還可以通過在 FIRConfiguration 接口上調用 setLoggerLevel: 來更改代碼中的默認日志記錄級別。
斯威夫特 4 Firebase 4.10
在 AppDelegate.swift 中設置記錄器級別
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
這是完整的代碼:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseConfiguration().setLoggerLevel(FirebaseLoggerLevel.min)
FirebaseApp.configure()
return true
}
FIRConfiguration.sharedInstance().setLoggerLevel(.min)
FIRApp.configure()
在斯威夫特 4
默認情況下,Firebase Analytics 只會在生產+錯誤/警告中記錄 4 個 INFO 行。 如果一切正常,那應該是很少的輸出。 添加 -noFIRAnalyticsDebugEnabled 只會禁用調試級別的日志,並且始終記錄錯誤/警告。 如果您看到任何警告或錯誤,您可能需要采取措施解決問題。 如果記錄警告/錯誤,有些事情可能無法正常工作。 正確設置的應用程序不應記錄錯誤/警告。
Firebase 通知會記錄標記為 FIRInstanceID/* 的消息,並且始終會記錄錯誤/警告。
正如 djabi 所說,如果這些日志是 INFO、WARNING 或 ERROR,則不能禁用它們。
我想添加到 Nitin Gohel 的回答中,因為我無法發表評論: FirebaseAppDelegateProxyEnabled標志不是用於禁用日志。 如果您將其關閉,您將失去自動活動跟蹤功能,您需要添加來自 FIRAnalytics(AppDelegate) 的方法來自己處理 URL 和用戶活動。
添加到亞歷克斯的答案,來自https://firebase.google.com/docs/cloud-messaging/ios/client
FirebaseAppDelegateProxyEnabled
用於調整您的應用程序委托的方法
FCM API 在兩個關鍵領域執行方法調整:將您的 APNs 令牌映射到 FCM 注冊令牌並在下游消息回調處理期間捕獲分析數據。 不喜歡使用 swizzling 的開發人員可以通過在應用程序的 Info.plist 文件中添加標志FirebaseAppDelegateProxyEnabled並將其設置為 NO(布爾值)來禁用它。 指南的相關區域提供了啟用和不啟用方法調配的代碼示例。
我認為有一個很大且非常重要的混亂正在發生。
通過使用-FIRDebugDisabled
它將禁用調試模式,然后您的測量將在測試和開發過程中受到影響。
目前無法同時啟用調試模式和禁用日志。 所以FirebaseConfiguration.shared.setLoggerLevel(.min)
基本上只能在非調試模式下工作。
作為解決方法,您可以使用僅用於Xcode 控制台日志記錄的-noFIRAnalyticsDebugEnabled
,這不會禁用您的調試模式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.