FirebaseLogger.swift 1.5 KB

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