美文网首页
ios swift log简单管理使用

ios swift log简单管理使用

作者: wenju | 来源:发表于2022-04-20 13:53 被阅读0次

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
    }
}

相关文章

网友评论

      本文标题:ios swift log简单管理使用

      本文链接:https://www.haomeiwen.com/subject/ljjvertx.html