Guest User

Untitled

a guest
Jan 24th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. //
  2. // Logger.swift
  3. //
  4. //
  5. // Created by Elon on 23/01/2019.
  6. // Copyright Β© 2019 Elon. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10.  
  11. struct Log {
  12.  
  13. private enum LogLevel: String {
  14. case verbose = "πŸ“’ VERBOSE"
  15. case debug = "πŸ›  DEBUG"
  16. case info = "πŸ’‘ INFO"
  17. case warning = "⚠️ WARNING"
  18. case error = "🚨 ERROR"
  19. }
  20.  
  21. private static func timeString() -> String {
  22. let now = Date()
  23. let dateFormatter = DateFormatter()
  24. dateFormatter.locale = Locale(identifier: "ko_KR") // λ‘œμΌ€μΌ μ„€μ •
  25. dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss.SSSS" // λ‚ μ§œ ν˜•μ‹ μ„€μ •
  26. let dateNow = dateFormatter.string(from: now)
  27.  
  28. return dateNow
  29. }
  30.  
  31. private static func logger(_ level: LogLevel, fileName: String, line: Int, funcName: String, output: Any...) {
  32. #if DEBUG
  33. if output.count < 2 {
  34. guard let printOut = output.first else { return }
  35. print("\(timeString()) \(level) \(printOut) -> \(funcName) Line: \(line) \(fileName)")
  36. } else {
  37. print("\(timeString()) \(level) ")
  38. for i in output {
  39. print(i)
  40. }
  41.  
  42. print(" -> \(funcName) Line: \(line) \(fileName)")
  43. }
  44. #endif
  45. }
  46.  
  47. static func v(fileName: String = #file, line: Int = #line, funcName: String = #function, _ output: Any...) {
  48. logger(.verbose, fileName: fileName, line: line, funcName: funcName, output: output)
  49. }
  50.  
  51. static func d(fileName: String = #file, line: Int = #line, funcName: String = #function, _ output: Any...) {
  52. logger(.debug, fileName: fileName, line: line, funcName: funcName, output: output)
  53. }
  54.  
  55. static func i(fileName: String = #file, line: Int = #line, funcName: String = #function, _ output: Any...) {
  56. logger(.info, fileName: fileName, line: line, funcName: funcName, output: output)
  57. }
  58.  
  59. static func w(fileName: String = #file, line: Int = #line, funcName: String = #function, _ output: Any...) {
  60. logger(.warning, fileName: fileName, line: line, funcName: funcName, output: output)
  61. }
  62.  
  63. static func e(fileName: String = #file, line: Int = #line, funcName: String = #function, _ output: Any...) {
  64. logger(.error, fileName: fileName, line: line, funcName: funcName, output: output)
  65. }
  66. }
Add Comment
Please, Sign In to add comment