Guest User

Untitled

a guest
May 20th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. final class Logger{
  2.  
  3. //A trick to see the expected results - Put the macros as the function's default values and the values of the macro will be of the function's caller
  4. class func log(_ logType:LogType, _ logMessage: String, file: String = #file, functionName: String = #function, lineNumber: Int = #line) {
  5.  
  6. //Do some checkups here
  7. //For example:
  8. // guard Config.environment == .debug else {
  9. // return
  10. // }
  11.  
  12. //Get only the file name without the full path
  13. var filename = (file as NSString).lastPathComponent
  14. filename = filename.components(separatedBy: ".")[0]
  15.  
  16. //Generate current date string
  17. let currentDate = Date()
  18. let df = DateFormatter()
  19. df.dateFormat = "HH:mm:ss.SSS"
  20. let dateString = df.string(from: currentDate)
  21.  
  22. //Print
  23. print("┌─────────────────────────────────────────────────────────────────────────")
  24. print("│ \(dateString) \n│ \(filename).\(functionName) (\(lineNumber)) [\(logType.capitalLetter)] \(logType.symbol)")
  25. print("└─────────────────────────────────────────────────────────────────────────")
  26. print("\(logMessage)\n")
  27.  
  28. }
  29. }
Add Comment
Please, Sign In to add comment