Created
December 5, 2022 08:56
-
-
Save iamchiwon/950d895931400019d4bfac71fad8abd9 to your computer and use it in GitHub Desktop.
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
import Foundation | |
private func filename(_ path: String) -> String { | |
guard let filename = path.split(separator: "/").last else { return path } | |
return String(filename.prefix(upTo: filename.index(filename.endIndex, offsetBy: -6))) | |
} | |
private func functionName(_ function: String) -> String { | |
guard let functionName = function.split(separator: "(").first else { return function } | |
return String(functionName) | |
} | |
private var lastTimeInMilli = timeInMilli() | |
private func timeInMilli() -> UInt64 { | |
UInt64(Date().timeIntervalSince1970 * 1000.0) | |
} | |
func TLog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
#if DEBUG | |
let last = lastTimeInMilli | |
let now = timeInMilli() | |
let gap = now - last | |
print("⏱ [\(filename(file))]\(functionName(function))(\(line))(\(now)-\(gap): \(message)") | |
lastTimeInMilli = now | |
#endif | |
} | |
func VLog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
#if DEBUG | |
print("📢 [\(filename(file))]\(functionName(function))(\(line)): \(message)") | |
#endif | |
} | |
func DLog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
#if DEBUG | |
print("🐞 [\(filename(file))]\(functionName(function))(\(line)): \(message)") | |
#endif | |
} | |
func DLog<T>(with m: () -> T, file: String = #file, function: String = #function, line: Int = #line) { | |
#if DEBUG | |
print("🐞 [\(filename(file))]\(functionName(function))(\(line)): \(m())") | |
#endif | |
} | |
func SLog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
print("📣 [\(filename(file))]\(functionName(function))(\(line)): \(message)") | |
} | |
func WLog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
print("⚠️ [\(filename(file))]\(functionName(function))(\(line)): \(message)") | |
} | |
func ELog(error: Error, file: String = #file, function: String = #function, line: Int = #line) { | |
print("🚫 [\(filename(file))]\(functionName(function))(\(line)): \(error.localizedDescription)") | |
} | |
func ELog<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) { | |
print("🚫 [\(filename(file))]\(functionName(function))(\(line)): \(message)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment