OSLog.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // OSLog.swift
  3. // ShareClient
  4. //
  5. // Created by Nathaniel Hamming on 2019-12-19.
  6. // Copyright © 2019 Mark Wilson. All rights reserved.
  7. //
  8. import os.log
  9. extension OSLog {
  10. convenience init(category: String) {
  11. self.init(subsystem: "com.loopkit.ShareClient", category: category)
  12. }
  13. func debug(_ message: StaticString, _ args: CVarArg...) {
  14. log(message, type: .debug, args)
  15. }
  16. func info(_ message: StaticString, _ args: CVarArg...) {
  17. log(message, type: .info, args)
  18. }
  19. func `default`(_ message: StaticString, _ args: CVarArg...) {
  20. log(message, type: .default, args)
  21. }
  22. func error(_ message: StaticString, _ args: CVarArg...) {
  23. log(message, type: .error, args)
  24. }
  25. private func log(_ message: StaticString, type: OSLogType, _ args: [CVarArg]) {
  26. switch args.count {
  27. case 0:
  28. os_log(message, log: self, type: type)
  29. case 1:
  30. os_log(message, log: self, type: type, args[0])
  31. case 2:
  32. os_log(message, log: self, type: type, args[0], args[1])
  33. case 3:
  34. os_log(message, log: self, type: type, args[0], args[1], args[2])
  35. case 4:
  36. os_log(message, log: self, type: type, args[0], args[1], args[2], args[3])
  37. case 5:
  38. os_log(message, log: self, type: type, args[0], args[1], args[2], args[3], args[4])
  39. default:
  40. os_log(message, log: self, type: type, args)
  41. }
  42. }
  43. }