将此代码放到AppDelegate.swift中就可以了,会自动变成全局可以访问的函数
func GGLog<T>(message : T, file : String = #file, funcName : String = #function, lineNum : Int = #line) {
#if DEBUG
let fileName = (file as NSString).lastPathComponent
print("\(fileName):[\(funcName)](\(lineNum))-\(message)")
#endif
}
自定义了logger级别
enum MPLogLevel : Int {
case debug = 0
case info = 5
case warning = 10
case error = 15
public func name() -> String {
var readableName: String
switch (self) {
case .debug:
readableName = "D"
case .info:
readableName = "I"
case .warning:
readableName = "W"
case .error:
readableName = "E"
}
return readableName
}
}
func GGLog<T>(level: MPLogLevel, message : T, file : String = #file, funcName : String = #function, lineNum : Int = #line) {
#if DEBUG
let fileName = (file as NSString).lastPathComponent.split(separator: ".").first!
print("[\(level.name())]: \(fileName)✽[\(funcName)]✽(\(lineNum))🏀 \(message)")
#endif
}
网友评论