ios swift log简单管理使用

log日志管理,方便后面使用

public class WLog: NSObject {
    static func i(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
        Log.info.cat(message)
    }
    
    static func s(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
        Log.success.cat(message)
    }
    
    static func e(_ message: T, file: String = #file, method: String = #function, line: Int = #line){
        Log.error.cat(message)
    }
    
    static func w(_ 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(_ message: T, file: String = #file, method: String = #function, line: Int = #line) {
        self.info.cat(message)
    }

    // 输入日志,根据类型,区别符号
    //
    // - Parameters:
    //- message: 显示的信息
    func cat(_ 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简单管理使用)