自定义日志函数:
- 打印文件名
- 打印类名
- 打印函数名
- 打印自定义消息
第一步:swift开启debug宏
第二步:自定义print函数
func LZSportLog<T>(obj: NSObject, message: T, file: String = #file, method: String = #function, line: Int = #line) -> () { printLog(obj:obj, message: message, file:file, method:method, line:line) } func printLog<T>(obj: NSObject, message: T, file: String = #file, method: String = #function, line: Int = #line) { #if DEBUG print("\\((file as NSString).lastPathComponent)[\\(line)], \\(String(describing: type(of: obj))):\\(method) \\(message)") #endif }