개발하면서 로그찍을 일이 많아 로그종류 / 시간 / 파일경로 / 클래스 / 함수명 / 라인수 / 복수의 데이터가 표시되게 만들어봤습니다. 

글로벌로 선언해서 사용하면 됩니다.

enum eDirection: Int {
    case UI,SEND,RECEIVE,WEBVIEW,SCHEME,OBSERVER,PUSH,ETC,ERROR
}

func log<T>(direction: eDirection,
                        ofType value: T,
                        file: String = #file,
                        function: String = #function,
                        line: Int = #line,
                    datas: Any?...){
       
    
    #if DEBUG
    let now = Date()
    let formatter = DateFormatter()
    formatter.locale = Locale(identifier:"ko_KR")
    formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
    formatter.timeZone = TimeZone(abbreviation: "KST")
    let time = formatter.string(from: now)
    
    print("\n===============================================================================\n")
    switch direction {
    case .UI:
        print("💚💚💚[ \(direction) LOG : \(String(describing: time)) ]💚💚💚")
    case .SEND:
        print("🔺🔺🔺[ \(direction) LOG : \(String(describing: time)) ]🔺🔺🔺")
    case .RECEIVE:
        print("🔻🔻🔻[ \(direction) LOG : \(String(describing: time)) ]🔻🔻🔻")
    case .WEBVIEW:
        print("💜💜💜[ \(direction) LOG : \(String(describing: time)) ]💜💜💜")
    case .SCHEME:
        print("⚡️⚡️⚡️[ \(direction) LOG : \(String(describing: time)) ]⚡️⚡️⚡️")
    case .OBSERVER:
        print("📩📩📩[ \(direction) LOG : \(String(describing: time)) ]📩📩📩")
    case .PUSH:
        print("📬📬📬[ \(direction) LOG : \(String(describing: time)) ]📬📬📬")
    case .ETC:
        print("💛💛💛[ \(direction) LOG : \(String(describing: time)) ]💛💛💛")
    case .ERROR:
        print("☠️☠️☠️[ \(direction) LOG : \(String(describing: time)) ]☠️☠️☠️")
    }
    
    print("Log File : \(file)")
    print("\n[Log ClassName] \(type(of: value as Any))")
    print("[Log Function ( \(line) Line )] \(function)")
    
    if datas[0] != nil {
        var index = 1
        print("\n[Log Data]")
        for data in datas {
            print("Data Value[\(index)] : \(String(describing: data ?? "NULL"))")
            index += 1
        }
    }
    
    print("\n===============================================================================")
    #endif
}

 | 사용방법

Ex1)
log(direction: .ETC, ofType: self, datas:
            "앱버전 : \(String(describing: appVersion()!))",
            "UUID : \(String(describing: UIDevice.deviceUUID!))",
            "NSUUID : \(String(describing: UIDevice.deviceNSUUID))",
            "국가코드 : \(UserData.deviceLocale.deviceRegionCode)",
            "디바이스 언어코드 : \(UserData.deviceLocale.deviceLanguageCode)",
            "앱 설정 언어코드 : \(UserData.deviceLocale.settingLanguageCode)",
            "디바이스 시스템 이름 : \(String(describing: UIDevice.deviceSystemName))",
            "디바이스 이름 : \(String(describing: UIDevice.deviceName))",
            "디바이스 버전 : \(String(describing: UIDevice.deviceSystemVersion))",
            "디바이스 제품이름 : \(String(describing: UIDevice.deviceModel))",
            "디바이스 제품모델 : \(UIDevice.modelName)")
            
            
===============================================================================

💛💛💛[ ETC LOG : 2021-11-16 14:48:34 ]💛💛💛
Log File : /Users/xxxxxxx/Documents/GitHub/xxxxxx/AppDelegate.swift

[Log ClassName] AppDelegate
[Log Function ( 117 Line )] application(_:didFinishLaunchingWithOptions:)

[Log Data]
Data Value[1] : 앱버전 : 1.0.4
Data Value[2] : UUID : 1ED0A60C-B338-4E44-8FD3-64F0B3B4681F
Data Value[3] : NSUUID : BA9FAB13-2668-46A5-AA4C-03D8A61A8F8F
Data Value[4] : 국가코드 : KR
Data Value[5] : 디바이스 언어코드 : ko
Data Value[6] : 앱 설정 언어코드 : ko
Data Value[7] : 디바이스 시스템 이름 : iOS
Data Value[8] : 디바이스 이름 : Dong Oh의 iPhone
Data Value[9] : 디바이스 버전 : 15.1
Data Value[10] : 디바이스 제품이름 : iPhone
Data Value[11] : 디바이스 제품모델 : iPhone Xs Max

===============================================================================

Ex2)
log(direction: .RECEIVE, ofType: self, datas: "***>Device Token - \(deviceTokenString)")

===============================================================================

🔻🔻🔻[ RECEIVE LOG : 2021-11-16 14:48:35 ]🔻🔻🔻
Log File : /Users/xxxxxxxx/Documents/GitHub/xxxxxxx/AppDelegate.swift

[Log ClassName] AppDelegate
[Log Function ( 249 Line )] application(_:didRegisterForRemoteNotificationsWithDeviceToken:)

[Log Data]
Data Value[1] : ***>Device Token - f46c68caecc7d1d80eb3a40e6552c3679a63b741266cbb2bcb282d82534a2d35

===============================================================================

+ Recent posts