OSLog.swift 1.4 KB

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