Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class Logger{
- //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
- class func log(_ logType:LogType, _ logMessage: String, file: String = #file, functionName: String = #function, lineNumber: Int = #line) {
- //Do some checkups here
- //For example:
- // guard Config.environment == .debug else {
- // return
- // }
- //Get only the file name without the full path
- var filename = (file as NSString).lastPathComponent
- filename = filename.components(separatedBy: ".")[0]
- //Generate current date string
- let currentDate = Date()
- let df = DateFormatter()
- df.dateFormat = "HH:mm:ss.SSS"
- let dateString = df.string(from: currentDate)
- //Print
- print("┌─────────────────────────────────────────────────────────────────────────")
- print("│ \(dateString) \n│ \(filename).\(functionName) (\(lineNumber)) [\(logType.capitalLetter)] \(logType.symbol)")
- print("└─────────────────────────────────────────────────────────────────────────")
- print("\(logMessage)\n")
- }
- }
Add Comment
Please, Sign In to add comment