log日志打印

import Foundation

class Log{

    public static func verbose<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
            let fileName = (file as NSString).lastPathComponent
            print("------> ?? [VERBOSE] \(fileName):\(line) \(function) : \(message) ??")
        #endif
    }

    public static func debug<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
            let fileName = (file as NSString).lastPathComponent
            let dformatter = DateFormatter()
            dformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let dateStr = dformatter.string(from: Date())
            print("------> ?? [DEBUG] \(dateStr) \(fileName):\(line) \(function) : \(message) ??")
        #endif
    }

    public static func info<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
            let fileName = (file as NSString).lastPathComponent
            let dformatter = DateFormatter()
            dformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let dateStr = dformatter.string(from: Date())
            print("------> ?? [INFO] \(dateStr) \(fileName):\(line) \(function) : \(message) ??")
        #endif
    }

    public static func warning<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
            let fileName = (file as NSString).lastPathComponent
            let dformatter = DateFormatter()
            dformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let dateStr = dformatter.string(from: Date())
            print("------> ?? [WARNING] \(dateStr) \(fileName):\(line) \(function) : \(message) ??")
        #endif
    }

    public static func error<T>(_ message: T, file: String = #file, function: String = #function, line: Int = #line) {
        #if DEBUG
            let fileName = (file as NSString).lastPathComponent
            let dformatter = DateFormatter()
            dformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let dateStr = dformatter.string(from: Date())
            print("------> ?? [ERROR] \(dateStr) \(fileName):\(line) \(function) : \(message) ??")
        #endif
    }
}

使用

Log.debug("characteristic \(characteristic.uuid.uuidString)")

打印的log

------> ?? [DEBUG] 2023-06-15 20:27:11 ViewController.swift:162 peripheral(_:didDiscoverCharacteristicsFor:error:) : characteristic F195B8FB-A9E2-4401-858B-2F87A06928A8 ??
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容