FirestoreLogger.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2023 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. */
  16. import Foundation
  17. import OSLog
  18. /// Base FirestoreLogger class
  19. /// Logging categories can be created by extending FirestoreLogger and defining a static FirestoreLogger var with your category
  20. ///
  21. /// ```
  22. /// extension FirestoreLogger {
  23. /// static var myCategory = FirestoreLogger(category: "myCategory")
  24. /// }
  25. /// ```
  26. ///
  27. /// To use your extension, call
  28. /// ```
  29. /// FirestoreLogger.myCategory.log(msg, vars)
  30. /// ```
  31. /// See ReferenceableObject.swift for the FirestoreLogger extension for an example
  32. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  33. class FirestoreLogger: OSLog {
  34. private let firestoreSubsystem = "com.google.firebase.firestore"
  35. init(category: String) {
  36. super.init(subsystem: firestoreSubsystem, category: category)
  37. }
  38. func debug(_ message: StaticString, _ args: CVarArg...) {
  39. os_log(message, log: self, type: .debug, args)
  40. }
  41. func info(_ message: StaticString, _ args: CVarArg...) {
  42. os_log(message, log: self, type: .info, args)
  43. }
  44. func log(_ message: StaticString, _ args: CVarArg...) {
  45. os_log(message, log: self, type: .default, args)
  46. }
  47. func error(_ message: StaticString, _ args: CVarArg) {
  48. os_log(message, log: self, type: .error, args)
  49. }
  50. func fault(_ message: StaticString, _ args: CVarArg) {
  51. os_log(message, log: self, type: .fault, args)
  52. }
  53. }