swift Log

2021-12-21  本文已影响0人  我会回来的

一 : 一种方法

自定义Log 

#function :  当前画面的方法名字 

代码如下:

func XMGLog(_messsage : T, file:String=#file,funcName:String=#function,lineNum:Int=#line) {

        #if DEBUG

        //lastPathComponent

        letfileName = (fileasNSString).lastPathComponent

        print("\(fileName):(\(lineNum))-\(messsage)")

        #endif

    }

打印:文件(行数)内容

二: 二种方法 

获取当前时间  +  相关内容 

fun clog(_message:String,

       function:String=#function,

       file:String=#file,

       line:Int=#line) {

           varfilename = file

           ifletmatch = filename.range(of:"[^/]*$",options: .regularExpression) {

               filename = filename.substring(with: match)

           }

              letdate =Date()

              lettimeFormatter =DateFormatter()

              //日期显示格式,可按自己需求显示

              timeFormatter.dateFormat="yyy-MM-dd' at 'HH:mm:ss.SSS"

              letstrNowTime = timeFormatter.string(from: date)asString

        LogView.logView?.setLog("\(strNowTime):\(filename):L\(line):\(function) \"\(message)\"")

   }

上一篇 下一篇

猜你喜欢

热点阅读