DevEventConsoleLogger.swift 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. import Foundation
  16. class DevEventConsoleLogger: EventGDTLoggerProtocol {
  17. private let commandLineArgument = "-FIRSessionsDebugEvents"
  18. func logEvent(event: SessionStartEvent, completion: @escaping (Result<Void, Error>) -> Void) {
  19. if !ProcessInfo.processInfo.arguments.contains(commandLineArgument) {
  20. return
  21. }
  22. let proto = event.encodeDecodeEvent()
  23. prettyPrint(proto: proto)
  24. }
  25. func prettyPrint(proto: firebase_appquality_sessions_SessionEvent) {
  26. let logOutput = """
  27. Logging Session Event due to \"\(commandLineArgument)\" command line argument
  28. Session Event:
  29. event_type: \(proto.event_type)
  30. session_data
  31. session_id: \(proto.session_data.session_id.description)
  32. previous_session_id: \(proto.session_data.previous_session_id.description)
  33. event_timestamp_us: \(proto.session_data.event_timestamp_us)
  34. data_collection_status
  35. crashlytics: \(proto.session_data.data_collection_status.crashlytics)
  36. performance: \(proto.session_data.data_collection_status.performance)
  37. application_info
  38. app_id: \(proto.application_info.app_id.description)
  39. device_model: \(proto.application_info.device_model.description)
  40. development_platform_name: \(proto.application_info.development_platform_name.description)
  41. development_platform_version: \(proto.application_info.development_platform_version
  42. .description)
  43. session_sdk_version: \(proto.application_info.session_sdk_version.description)
  44. apple_app_info
  45. bundle_short_version: \(proto.application_info.apple_app_info.bundle_short_version
  46. .description)
  47. network_connection_info
  48. network_type: \(proto.application_info.apple_app_info.network_connection_info
  49. .network_type.rawValue)
  50. mobile_subtype: \(proto.application_info.apple_app_info.network_connection_info
  51. .mobile_subtype.rawValue)
  52. os_name: \(proto.application_info.apple_app_info.os_name.description)
  53. mcc_mnc: \(proto.application_info.apple_app_info.mcc_mnc.description)
  54. log_environment: \(proto.application_info.log_environment)
  55. """
  56. Logger.logInfo(logOutput)
  57. }
  58. }