DevEventConsoleLogger.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #if SWIFT_PACKAGE
  17. import FirebaseSessionsObjC
  18. #endif // SWIFT_PACKAGE
  19. class DevEventConsoleLogger: EventGDTLoggerProtocol {
  20. private let commandLineArgument = "-FIRSessionsDebugEvents"
  21. func logEvent(event: SessionStartEvent, completion: @escaping (Result<Void, Error>) -> Void) {
  22. if !ProcessInfo.processInfo.arguments.contains(commandLineArgument) {
  23. return
  24. }
  25. let proto = event.encodeDecodeEvent()
  26. prettyPrint(proto: proto)
  27. }
  28. func prettyPrint(proto: firebase_appquality_sessions_SessionEvent) {
  29. let logOutput = """
  30. Printing Session Event due to \"\(commandLineArgument)\" command line argument
  31. Session Event:
  32. event_type: \(proto.event_type)
  33. session_data
  34. session_id: \(proto.session_data.session_id.description)
  35. first_session_id: \(proto.session_data.first_session_id.description)
  36. session_index: \(proto.session_data.session_index)
  37. event_timestamp_us: \(proto.session_data.event_timestamp_us)
  38. firebase_installation_id: \(proto.session_data.firebase_installation_id.description)
  39. data_collection_status
  40. crashlytics: \(proto.session_data.data_collection_status.crashlytics)
  41. performance: \(proto.session_data.data_collection_status.performance)
  42. session_sampling_rate: \(proto.session_data.data_collection_status.session_sampling_rate)
  43. application_info
  44. app_id: \(proto.application_info.app_id.description)
  45. device_model: \(proto.application_info.device_model.description)
  46. development_platform_name: \(proto.application_info.development_platform_name.description)
  47. development_platform_version: \(proto.application_info.development_platform_version
  48. .description)
  49. session_sdk_version: \(proto.application_info.session_sdk_version.description)
  50. apple_app_info
  51. bundle_short_version: \(proto.application_info.apple_app_info.bundle_short_version
  52. .description)
  53. network_connection_info
  54. network_type: \(proto.application_info.apple_app_info.network_connection_info
  55. .network_type.rawValue)
  56. mobile_subtype: \(proto.application_info.apple_app_info.network_connection_info
  57. .mobile_subtype.rawValue)
  58. os_name: \(proto.application_info.apple_app_info.os_name.description)
  59. log_environment: \(proto.application_info.log_environment)
  60. """
  61. Logger.logInfo(logOutput)
  62. }
  63. }