ios swift log简单管理使用
2022-04-20 本文已影响0人
wenju
log日志管理,方便后面使用
public class WLog: NSObject {
static func i<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
Log.info.cat(message)
}
static func s<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
Log.success.cat(message)
}
static func e<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
Log.error.cat(message)
}
static func w<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
Log.warning.cat(message)
}
}
enum Log {
case info
case success
case error
case warning
}
extension Log {
// 输出默认info的日志
static func cat<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line) {
self.info.cat(message)
}
// 输入日志,根据类型,区别符号
//
// - Parameters:
//- message: 显示的信息
func cat<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line) {
#if DEBUG
var log: String
switch self {
case .info:
log = " 🎼 - " + "\(message)"
case .success:
log = " ✅ - " + "\(message)"
case .error:
log = " ❌ - " + "\(message)"
case .warning:
log = " ⚠️ - " + "\(message)"
}
print("\((file as NSString).lastPathComponent)[\(line)],\(method):\(log)")
#endif
}
}