DevEventConsoleLogger.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. session_sampling_rate: \(proto.session_data.data_collection_status.session_sampling_rate)
  38. application_info
  39. app_id: \(proto.application_info.app_id.description)
  40. device_model: \(proto.application_info.device_model.description)
  41. development_platform_name: \(proto.application_info.development_platform_name.description)
  42. development_platform_version: \(proto.application_info.development_platform_version
  43. .description)
  44. session_sdk_version: \(proto.application_info.session_sdk_version.description)
  45. apple_app_info
  46. bundle_short_version: \(proto.application_info.apple_app_info.bundle_short_version
  47. .description)
  48. network_connection_info
  49. network_type: \(proto.application_info.apple_app_info.network_connection_info
  50. .network_type.rawValue)
  51. mobile_subtype: \(proto.application_info.apple_app_info.network_connection_info
  52. .mobile_subtype.rawValue)
  53. os_name: \(proto.application_info.apple_app_info.os_name.description)
  54. mcc_mnc: \(proto.application_info.apple_app_info.mcc_mnc.description)
  55. log_environment: \(proto.application_info.log_environment)
  56. """
  57. Logger.logInfo(logOutput)
  58. }
  59. }