Created
May 1, 2019 14:42
-
-
Save koingdev/827d1143e1d0dfc8e3a13c19bfc8c7a6 to your computer and use it in GitHub Desktop.
Simple Swift Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dPrint(_ item: Any) { | |
#if DEBUG | |
Swift.print(item) | |
#endif | |
} | |
final class Log { | |
private enum LogType: String { | |
case error = "[⛔️]" | |
case debug = "[ℹ️]" | |
case warning = "[⚠️]" | |
} | |
private static func sourceFileName(filePath: String) -> String { | |
let fileName = filePath.components(separatedBy: "/").last | |
return fileName ?? "" | |
} | |
static func error(_ object: Any, | |
fileName: String = #file, | |
line: Int = #line, | |
funcName: String = #function) { | |
dPrint("Log: \(LogType.error.rawValue) [\(sourceFileName(filePath: fileName))] [Line: \(line)] \(funcName) -> \(object)") | |
} | |
static func debug(_ object: Any, | |
fileName: String = #file, | |
line: Int = #line, | |
funcName: String = #function) { | |
dPrint("Log: \(LogType.debug.rawValue) [\(sourceFileName(filePath: fileName))] [Line: \(line)] \(funcName) -> \(object)") | |
} | |
static func warning(_ object: Any, | |
fileName: String = #file, | |
line: Int = #line, | |
funcName: String = #function) { | |
dPrint("Log: \(LogType.warning.rawValue) [\(sourceFileName(filePath: fileName))] [Line: \(line)] \(funcName) -> \(object)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment