FirebaseLogger.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2024 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 OSLog
  16. public struct FirebaseProduct {
  17. var name: String
  18. public init(name: String) {
  19. self.name = name
  20. }
  21. }
  22. public class FirebaseLogger {
  23. let subsystem: String = "com.google.firebase"
  24. let firebaseProduct: FirebaseProduct
  25. private lazy var logger: FirebaseInternalLog = {
  26. if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
  27. return FirebaseInternalLogger(subsystem: subsystem, category: firebaseProduct.name)
  28. } else {
  29. return OSLog(subsystem: subsystem, category: firebaseProduct.name)
  30. }
  31. }()
  32. public init(firebaseProduct: FirebaseProduct) {
  33. self.firebaseProduct = firebaseProduct
  34. }
  35. public func notice(_ message: String) {
  36. logger.notice(message)
  37. }
  38. public func info(_ message: String) {
  39. logger.info(message)
  40. }
  41. public func debug(_ message: String) {
  42. logger.debug(message)
  43. }
  44. public func warning(_ message: String) {
  45. logger.warning(message)
  46. }
  47. public func error(_ message: String) {
  48. logger.error(message)
  49. }
  50. public func fault(_ message: String) {
  51. logger.fault(message)
  52. }
  53. }