DeviceLogger.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import os
  16. /// Enum of debug messages.
  17. // TODO: Create list of all possible messages with code - according to format.
  18. enum LoggerMessageCode {
  19. case modelDownloaded
  20. case downloadedModelMovedToURL
  21. case analyticsEventEncodeError
  22. case telemetryInitError
  23. case backgroundDownloadError
  24. }
  25. /// On-device logger.
  26. class DeviceLogger {
  27. /// Log event on device.
  28. static func logEvent(level: OSLogType, category: OSLog, message: StaticString,
  29. messageCode: LoggerMessageCode) {
  30. // TODO: Replace with GULLogBasic.
  31. os_log(message, log: category, type: level)
  32. }
  33. }
  34. /// Extension to categorize on-device logging.
  35. extension OSLog {
  36. private static let subsystem: String = {
  37. let bundleID = Bundle.main.bundleIdentifier ?? ""
  38. return "com.google.firebaseml.\(bundleID)"
  39. }()
  40. /// List of logging categories.
  41. static let modelDownload = OSLog(subsystem: subsystem, category: "model-download")
  42. static let analytics = OSLog(subsystem: subsystem, category: "analytics")
  43. }