FirebaseInternalLog.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. protocol FirebaseInternalLog {
  17. func notice(_ message: String)
  18. func info(_ message: String)
  19. func debug(_ message: String)
  20. func warning(_ message: String)
  21. func error(_ message: String)
  22. func fault(_ message: String)
  23. }
  24. extension OSLog: FirebaseInternalLog {
  25. func notice(_ message: String) {
  26. os_log("%s", log: self, type: .default, message)
  27. }
  28. func info(_ message: String) {
  29. os_log("%s", log: self, type: .info, message)
  30. }
  31. func debug(_ message: String) {
  32. os_log("%s", log: self, type: .debug, message)
  33. }
  34. func warning(_ message: String) {
  35. os_log("%s", log: self, type: .default, message)
  36. }
  37. func error(_ message: String) {
  38. os_log("%s", log: self, type: .error, message)
  39. }
  40. func fault(_ message: String) {
  41. os_log("%s", log: self, type: .fault, message)
  42. }
  43. }
  44. @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
  45. class FirebaseInternalLogger: FirebaseInternalLog {
  46. private let logger: Logger
  47. required init(subsystem: String, category: String) {
  48. logger = Logger(subsystem: subsystem, category: category)
  49. }
  50. func notice(_ message: String) {
  51. logger.notice("\(message)")
  52. }
  53. func info(_ message: String) {
  54. logger.info("\(message)")
  55. }
  56. func debug(_ message: String) {
  57. logger.debug("\(message)")
  58. }
  59. func warning(_ message: String) {
  60. logger.warning("\(message)")
  61. }
  62. func error(_ message: String) {
  63. logger.error("\(message)")
  64. }
  65. func fault(_ message: String) {
  66. logger.fault("\(message)")
  67. }
  68. }