1 相關(guān)知識(shí)點(diǎn)
(1)獲取所在文件
let file : String = #file
// 獲取文件的最后路徑
let filepath = (file as NSString).lastPathComponent
(2)獲取在的方法
let fun = #function
(3)獲取在的行數(shù)
let line : Int = #line
2 自定義log
(1)在AppDelegate中定義一個(gè)全局函數(shù)
func JLLog<T>(message : T, file : String = #file, line : Int = #line){
#if DEBUG
let filepath = (file as NSString).lastPathComponent
let fun = #function
print("\(filepath)-\(fun)-[\(line)]-\(message)")
#endif
}
(2)調(diào)用的地方傳入message參數(shù)舀患,比如:
JLLog(message: "123")
(3)在debug下打印旷坦,在 release下不打悠煌琛:
默認(rèn)情況下色瘩,debug模式有DEBUG標(biāo)簽,根據(jù)DEBUG標(biāo)簽來(lái)判斷:
測(cè)試:
在debug下有打印,在release下沒(méi)有打印