IOS-1480 Remove logging in favor of toolbox. IOS-1480
authorDirk Zimmermann <dz@pep.security>
Thu, 21 Feb 2019 13:42:30 +0100
branchIOS-1480
changeset 1295a9a46e997c07
parent 1294 e56317c5027a
child 1296 520887801fe6
IOS-1480 Remove logging in favor of toolbox.
MessageModel/MessageModel.xcodeproj/project.pbxproj
MessageModel/MessageModel/NetworkService/Util/Log+ASL.swift
MessageModel/MessageModel/NetworkService/Util/Log.swift
MessageModel/MessageModel/NetworkService/Util/Logger.swift
     1.1 --- a/MessageModel/MessageModel.xcodeproj/project.pbxproj	Thu Feb 21 13:42:30 2019 +0100
     1.2 +++ b/MessageModel/MessageModel.xcodeproj/project.pbxproj	Thu Feb 21 13:42:30 2019 +0100
     1.3 @@ -58,16 +58,13 @@
     1.4  		43EA4848221E9518006E8F83 /* EmailConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47EB221E9518006E8F83 /* EmailConnectInfo.swift */; };
     1.5  		43EA4849221E9518006E8F83 /* ImapFolderBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47EC221E9518006E8F83 /* ImapFolderBuilder.swift */; };
     1.6  		43EA484B221E9518006E8F83 /* CdMessagePredicateFactory+Imap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47EF221E9518006E8F83 /* CdMessagePredicateFactory+Imap.swift */; };
     1.7 -		43EA484C221E9518006E8F83 /* Log+ASL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F0221E9518006E8F83 /* Log+ASL.swift */; };
     1.8  		43EA484D221E9518006E8F83 /* Folder+Imap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F1221E9518006E8F83 /* Folder+Imap.swift */; };
     1.9 -		43EA484E221E9518006E8F83 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F2221E9518006E8F83 /* Log.swift */; };
    1.10  		43EA484F221E9518006E8F83 /* Message+FakeMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F3221E9518006E8F83 /* Message+FakeMessage.swift */; };
    1.11  		43EA4850221E9518006E8F83 /* Folder+VirtualMailbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F5221E9518006E8F83 /* Folder+VirtualMailbox.swift */; };
    1.12  		43EA4851221E9518006E8F83 /* PantomimeFolderAttribute+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F6221E9518006E8F83 /* PantomimeFolderAttribute+Extensions.swift */; };
    1.13  		43EA4852221E9518006E8F83 /* GmailSpecificInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F7221E9518006E8F83 /* GmailSpecificInformation.swift */; };
    1.14  		43EA4853221E9518006E8F83 /* ProviderSpecificInformationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F8221E9518006E8F83 /* ProviderSpecificInformationProtocol.swift */; };
    1.15  		43EA4854221E9518006E8F83 /* ConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47F9221E9518006E8F83 /* ConnectInfo.swift */; };
    1.16 -		43EA4855221E9518006E8F83 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47FA221E9518006E8F83 /* Logger.swift */; };
    1.17  		43EA4856221E9518006E8F83 /* CdMessage+Pantomime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47FB221E9518006E8F83 /* CdMessage+Pantomime.swift */; };
    1.18  		43EA4857221E9518006E8F83 /* Attachment+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47FC221E9518006E8F83 /* Attachment+Extension.swift */; };
    1.19  		43EA4858221E9518006E8F83 /* ConnectionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA47FD221E9518006E8F83 /* ConnectionManager.swift */; };
    1.20 @@ -246,16 +243,13 @@
    1.21  		43EA47EB221E9518006E8F83 /* EmailConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailConnectInfo.swift; sourceTree = "<group>"; };
    1.22  		43EA47EC221E9518006E8F83 /* ImapFolderBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImapFolderBuilder.swift; sourceTree = "<group>"; };
    1.23  		43EA47EF221E9518006E8F83 /* CdMessagePredicateFactory+Imap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CdMessagePredicateFactory+Imap.swift"; sourceTree = "<group>"; };
    1.24 -		43EA47F0221E9518006E8F83 /* Log+ASL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Log+ASL.swift"; sourceTree = "<group>"; };
    1.25  		43EA47F1221E9518006E8F83 /* Folder+Imap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Folder+Imap.swift"; sourceTree = "<group>"; };
    1.26 -		43EA47F2221E9518006E8F83 /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
    1.27  		43EA47F3221E9518006E8F83 /* Message+FakeMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Message+FakeMessage.swift"; sourceTree = "<group>"; };
    1.28  		43EA47F5221E9518006E8F83 /* Folder+VirtualMailbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Folder+VirtualMailbox.swift"; sourceTree = "<group>"; };
    1.29  		43EA47F6221E9518006E8F83 /* PantomimeFolderAttribute+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PantomimeFolderAttribute+Extensions.swift"; sourceTree = "<group>"; };
    1.30  		43EA47F7221E9518006E8F83 /* GmailSpecificInformation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GmailSpecificInformation.swift; sourceTree = "<group>"; };
    1.31  		43EA47F8221E9518006E8F83 /* ProviderSpecificInformationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProviderSpecificInformationProtocol.swift; sourceTree = "<group>"; };
    1.32  		43EA47F9221E9518006E8F83 /* ConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectInfo.swift; sourceTree = "<group>"; };
    1.33 -		43EA47FA221E9518006E8F83 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
    1.34  		43EA47FB221E9518006E8F83 /* CdMessage+Pantomime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CdMessage+Pantomime.swift"; sourceTree = "<group>"; };
    1.35  		43EA47FC221E9518006E8F83 /* Attachment+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Attachment+Extension.swift"; sourceTree = "<group>"; };
    1.36  		43EA47FD221E9518006E8F83 /* ConnectionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionManager.swift; sourceTree = "<group>"; };
    1.37 @@ -600,13 +594,10 @@
    1.38  			isa = PBXGroup;
    1.39  			children = (
    1.40  				43EA47EF221E9518006E8F83 /* CdMessagePredicateFactory+Imap.swift */,
    1.41 -				43EA47F0221E9518006E8F83 /* Log+ASL.swift */,
    1.42  				43EA47F1221E9518006E8F83 /* Folder+Imap.swift */,
    1.43 -				43EA47F2221E9518006E8F83 /* Log.swift */,
    1.44  				43EA47F3221E9518006E8F83 /* Message+FakeMessage.swift */,
    1.45  				43EA47F4221E9518006E8F83 /* VirtualMailbox */,
    1.46  				43EA47F9221E9518006E8F83 /* ConnectInfo.swift */,
    1.47 -				43EA47FA221E9518006E8F83 /* Logger.swift */,
    1.48  				43EA47FB221E9518006E8F83 /* CdMessage+Pantomime.swift */,
    1.49  				43EA47FC221E9518006E8F83 /* Attachment+Extension.swift */,
    1.50  				43EA47FD221E9518006E8F83 /* ConnectionManager.swift */,
    1.51 @@ -1025,7 +1016,6 @@
    1.52  				43EA4864221E9518006E8F83 /* AuthMethod.swift in Sources */,
    1.53  				B718EF331F867015000CFB71 /* FilterBase.swift in Sources */,
    1.54  				43EA4852221E9518006E8F83 /* GmailSpecificInformation.swift in Sources */,
    1.55 -				43EA484E221E9518006E8F83 /* Log.swift in Sources */,
    1.56  				8BA887661DBF4076003B58F1 /* MessageReference.swift in Sources */,
    1.57  				43EA487B221E9518006E8F83 /* FetchMessagesOperation.swift in Sources */,
    1.58  				15F0F7B42136F68A002BE853 /* CdFolder+PredicateFactory.swift in Sources */,
    1.59 @@ -1099,7 +1089,6 @@
    1.60  				43F484461E8130A80028BC1A /* CdImapFields+Extension.swift in Sources */,
    1.61  				43EA4885221E9518006E8F83 /* StoreFolderOperation.swift in Sources */,
    1.62  				4358D1181DC5F6BF00385CC5 /* NSOrderedSet+Extension.swift in Sources */,
    1.63 -				43EA484C221E9518006E8F83 /* Log+ASL.swift in Sources */,
    1.64  				43EA487A221E9518006E8F83 /* ConcurrentBaseOperation.swift in Sources */,
    1.65  				43EA4877221E9518006E8F83 /* SyncFlagsToServerOperation.swift in Sources */,
    1.66  				8BE4607F1DB7B2FF008D63C6 /* CdIdentity.swift in Sources */,
    1.67 @@ -1133,7 +1122,6 @@
    1.68  				8BA887641DBF3D7E003B58F1 /* MessageKeyword.swift in Sources */,
    1.69  				43EA484F221E9518006E8F83 /* Message+FakeMessage.swift in Sources */,
    1.70  				43EA484D221E9518006E8F83 /* Folder+Imap.swift in Sources */,
    1.71 -				43EA4855221E9518006E8F83 /* Logger.swift in Sources */,
    1.72  				493B6D051E70589800364D60 /* SystemUtils.swift in Sources */,
    1.73  				434DC0D51DAE72D4007C98B8 /* Server.swift in Sources */,
    1.74  			);
     2.1 --- a/MessageModel/MessageModel/NetworkService/Util/Log+ASL.swift	Thu Feb 21 13:42:30 2019 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,213 +0,0 @@
     2.4 -//
     2.5 -//  Log+ASL.swift
     2.6 -//  pEp
     2.7 -//
     2.8 -//  Created by Dirk Zimmermann on 03.10.18.
     2.9 -//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    2.10 -//
    2.11 -
    2.12 -import Foundation
    2.13 -import asl
    2.14 -
    2.15 -class ASLLogger: ActualLoggerProtocol {
    2.16 -    func saveLog(severity: LoggingSeverity,
    2.17 -                 entity: String,
    2.18 -                 description: String,
    2.19 -                 comment: String) {
    2.20 -        let logMessage = asl_new(UInt32(ASL_TYPE_MSG))
    2.21 -
    2.22 -        asl_set(logMessage, ASL_KEY_SENDER, sender)
    2.23 -        asl_set(logMessage, ASL_KEY_FACILITY, entity)
    2.24 -        asl_set(logMessage, ASL_KEY_MSG, "\(description) [\(comment)]")
    2.25 -        asl_set(logMessage, ASL_KEY_LEVEL, "\(severity.aslLevel())")
    2.26 -
    2.27 -        let nowDate = Date()
    2.28 -        let dateString = "\(Int(nowDate.timeIntervalSince1970))"
    2.29 -        asl_set(logMessage, ASL_KEY_TIME, dateString)
    2.30 -
    2.31 -        asl_set(logMessage, ASL_KEY_READ_UID, "-1")
    2.32 -
    2.33 -        asl_send(self.consoleClient, logMessage)
    2.34 -        asl_free(logMessage)
    2.35 -    }
    2.36 -
    2.37 -    func retrieveLog() -> String {
    2.38 -        let query = asl_new(UInt32(ASL_TYPE_QUERY))
    2.39 -
    2.40 -        var result = asl_set_query(
    2.41 -            query,
    2.42 -            ASL_KEY_SENDER,
    2.43 -            sender,
    2.44 -            UInt32(ASL_QUERY_OP_EQUAL))
    2.45 -        ASLLogger.checkASLSuccess(result: result, comment: "asl_set_query ASL_KEY_SENDER")
    2.46 -
    2.47 -        let fromDate = Date(timeInterval: -600, since: Date())
    2.48 -        let fromDateString = "\(Int(fromDate.timeIntervalSince1970))"
    2.49 -        result = asl_set_query(
    2.50 -            query,
    2.51 -            ASL_KEY_TIME,
    2.52 -            fromDateString,
    2.53 -            UInt32(ASL_QUERY_OP_GREATER_EQUAL))
    2.54 -        ASLLogger.checkASLSuccess(result: result, comment: "asl_set_query ASL_KEY_TIME")
    2.55 -
    2.56 -        let theClient = createConsoleLogger()
    2.57 -
    2.58 -        let response = asl_search(theClient, query)
    2.59 -        var next = asl_next(response)
    2.60 -        var logString = ""
    2.61 -        while next != nil {
    2.62 -            let timeString = String(cString: asl_get(next, ASL_KEY_TIME))
    2.63 -            let messageString = String(cString: asl_get(next, ASL_KEY_MSG))
    2.64 -            let facilityString = String(cString: asl_get(next, ASL_KEY_FACILITY))
    2.65 -            let levelString = String(cString: asl_get(next, ASL_KEY_LEVEL))
    2.66 -
    2.67 -            let level = levelString.aslLevelStringToASL()
    2.68 -            let ownLevelString = level.criticalityString()
    2.69 -
    2.70 -            var dateString = "<NoTime>"
    2.71 -            if let dateInt = Int(timeString) {
    2.72 -                let date = Date(timeIntervalSince1970: TimeInterval(dateInt))
    2.73 -                dateString = "\(date)"
    2.74 -            }
    2.75 -
    2.76 -            if !logString.isEmpty {
    2.77 -                logString.append("\n")
    2.78 -            }
    2.79 -
    2.80 -            let stringToLog = "\(dateString) [\(ownLevelString)] [\(facilityString)] \(messageString)"
    2.81 -            logString.append(stringToLog)
    2.82 -
    2.83 -            next = asl_next(response)
    2.84 -        }
    2.85 -
    2.86 -        asl_free(query)
    2.87 -        asl_free(response)
    2.88 -        asl_free(theClient)
    2.89 -
    2.90 -        return logString
    2.91 -    }
    2.92 -
    2.93 -    init() {
    2.94 -        self.consoleClient = createConsoleLogger()
    2.95 -    }
    2.96 -
    2.97 -    deinit {
    2.98 -        asl_release(consoleClient)
    2.99 -    }
   2.100 -
   2.101 -    private let sender = "security.pEp.app.iOS"
   2.102 -
   2.103 -    private var consoleClient: aslclient?
   2.104 -
   2.105 -    private func createConsoleLogger() -> asl_object_t {
   2.106 -        return asl_open(self.sender, "default", 0)
   2.107 -    }
   2.108 -
   2.109 -    private static func checkASLSuccess(result: Int32, comment: String) {
   2.110 -        if result != 0 {
   2.111 -            print("error: \(comment)")
   2.112 -        }
   2.113 -    }
   2.114 -}
   2.115 -
   2.116 -extension LoggingSeverity {
   2.117 -    /**
   2.118 -     Maps the internal criticality of a log  message into a subsystem of ASL levels.
   2.119 -
   2.120 -     ASL has the following:
   2.121 -     * ASL_LEVEL_EMERG
   2.122 -     * ASL_LEVEL_ALERT
   2.123 -     * ASL_LEVEL_CRIT
   2.124 -     * ASL_LEVEL_ERR
   2.125 -     * ASL_LEVEL_WARNING
   2.126 -     * ASL_LEVEL_NOTICE
   2.127 -     * ASL_LEVEL_INFO
   2.128 -     * ASL_LEVEL_DEBUG
   2.129 -     */
   2.130 -    func aslLevel() -> Int32 {
   2.131 -        switch self {
   2.132 -        case .verbose:
   2.133 -            return ASL_LEVEL_DEBUG
   2.134 -        case .info:
   2.135 -            return ASL_LEVEL_NOTICE
   2.136 -        case .warning:
   2.137 -            return ASL_LEVEL_WARNING
   2.138 -        case .error:
   2.139 -            return ASL_LEVEL_ERR
   2.140 -        }
   2.141 -    }
   2.142 -}
   2.143 -
   2.144 -extension String {
   2.145 -    func aslLevelStringToASL() -> Int32 {
   2.146 -        switch self {
   2.147 -        case "0":
   2.148 -            return ASL_LEVEL_EMERG
   2.149 -        case "1":
   2.150 -            return ASL_LEVEL_ALERT
   2.151 -        case "2":
   2.152 -            return ASL_LEVEL_CRIT
   2.153 -        case "3":
   2.154 -            return ASL_LEVEL_ERR
   2.155 -        case "4":
   2.156 -            return ASL_LEVEL_WARNING
   2.157 -        case "5":
   2.158 -            return ASL_LEVEL_NOTICE
   2.159 -        case "6":
   2.160 -            return ASL_LEVEL_INFO
   2.161 -        case "7":
   2.162 -            return ASL_LEVEL_DEBUG
   2.163 -
   2.164 -        default:
   2.165 -            return ASL_LEVEL_DEBUG
   2.166 -        }
   2.167 -    }
   2.168 -}
   2.169 -
   2.170 -extension Int32 {
   2.171 -    func criticalityString() -> String {
   2.172 -        switch self {
   2.173 -        case ASL_LEVEL_EMERG:
   2.174 -            return "EMERG"
   2.175 -        case ASL_LEVEL_ALERT:
   2.176 -            return "ALERT"
   2.177 -        case ASL_LEVEL_CRIT:
   2.178 -            return "CRIT"
   2.179 -        case ASL_LEVEL_ERR:
   2.180 -            return "ERR"
   2.181 -        case ASL_LEVEL_WARNING:
   2.182 -            return "WARNING"
   2.183 -        case ASL_LEVEL_NOTICE:
   2.184 -            return "NOTICE"
   2.185 -        case ASL_LEVEL_INFO:
   2.186 -            return "INFO"
   2.187 -        case ASL_LEVEL_DEBUG:
   2.188 -            return "DEBUG"
   2.189 -        default:
   2.190 -            return "UNKNOWN"
   2.191 -        }
   2.192 -    }
   2.193 -
   2.194 -    func aslLevelString() -> String {
   2.195 -        switch self {
   2.196 -        case ASL_LEVEL_EMERG:
   2.197 -            return "ASL_LEVEL_EMERG"
   2.198 -        case ASL_LEVEL_ALERT:
   2.199 -            return "ASL_LEVEL_ALERT"
   2.200 -        case ASL_LEVEL_CRIT:
   2.201 -            return "ASL_LEVEL_CRIT"
   2.202 -        case ASL_LEVEL_ERR:
   2.203 -            return "ASL_LEVEL_ERR"
   2.204 -        case ASL_LEVEL_WARNING:
   2.205 -            return "ASL_LEVEL_WARNING"
   2.206 -        case ASL_LEVEL_NOTICE:
   2.207 -            return "ASL_LEVEL_NOTICE"
   2.208 -        case ASL_LEVEL_INFO:
   2.209 -            return "ASL_LEVEL_INFO"
   2.210 -        case ASL_LEVEL_DEBUG:
   2.211 -            return "ASL_LEVEL_DEBUG"
   2.212 -        default:
   2.213 -            return "ASL_LEVEL_UNKNOWN"
   2.214 -        }
   2.215 -    }
   2.216 -}
     3.1 --- a/MessageModel/MessageModel/NetworkService/Util/Log.swift	Thu Feb 21 13:42:30 2019 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,206 +0,0 @@
     3.4 -//
     3.5 -//  Log.swift
     3.6 -//  pEpForiOS
     3.7 -//
     3.8 -//  Created by Dirk Zimmermann on 08/04/16.
     3.9 -//  Copyright © 2016 p≡p Security S.A. All rights reserved.
    3.10 -//
    3.11 -
    3.12 -import os.log
    3.13 -
    3.14 -enum LoggingSeverity {
    3.15 -    case verbose
    3.16 -    case info
    3.17 -    case warning
    3.18 -    case error
    3.19 -}
    3.20 -
    3.21 -/**
    3.22 - Handling the actual logging.
    3.23 - */
    3.24 -protocol ActualLoggerProtocol {
    3.25 -    func saveLog(severity: LoggingSeverity,
    3.26 -                 entity: String,
    3.27 -                 description: String,
    3.28 -                 comment: String)
    3.29 -
    3.30 -    func retrieveLog() -> String
    3.31 -}
    3.32 -
    3.33 -/** Very primitive Logging class. */
    3.34 -@objc open class Log: NSObject {
    3.35 -    static public let shared: Log = {
    3.36 -        let instance = Log()
    3.37 -        return instance
    3.38 -    }()
    3.39 -
    3.40 -    static public func disableLog() {
    3.41 -        Log.shared.loggingQueue.addOperation() {
    3.42 -            Log.shared.logEnabled = false
    3.43 -        }
    3.44 -    }
    3.45 -
    3.46 -    static public func enableLog() {
    3.47 -        Log.shared.loggingQueue.addOperation() {
    3.48 -            Log.shared.logEnabled = true
    3.49 -        }
    3.50 -    }
    3.51 -
    3.52 -    static public func checkEnabled(_ block: ((Bool) -> ())?) {
    3.53 -        Log.shared.loggingQueue.addOperation() {
    3.54 -            let b = Log.shared.logEnabled
    3.55 -            block?(b)
    3.56 -        }
    3.57 -    }
    3.58 -
    3.59 -    static public func checklog(_ block: ((String?) -> ())?) {
    3.60 -        Log.shared.loggingQueue.addOperation() {
    3.61 -            let logString = Log.shared.internalLogger.retrieveLog()
    3.62 -            block?(logString)
    3.63 -        }
    3.64 -    }
    3.65 -
    3.66 -    static public func verbose(component: String, content: String) {
    3.67 -        Log.shared.saveLog(severity:.verbose,
    3.68 -                           entity: component, description: content, comment: "verbose")
    3.69 -    }
    3.70 -
    3.71 -    /** Somewhat verbose */
    3.72 -    static public func info(component: String, content: String) {
    3.73 -        Log.shared.saveLog(severity:.info,
    3.74 -                           entity: component, description: content, comment: "info")
    3.75 -    }
    3.76 -
    3.77 -    /** More important */
    3.78 -    static public func warn(component: String, content: String) {
    3.79 -        Log.shared.saveLog(severity:.warning,
    3.80 -                           entity: component, description: content, comment: "warn")
    3.81 -    }
    3.82 -
    3.83 -    static public func error(component: String, error: Error?) {
    3.84 -        if let err = error {
    3.85 -            Log.shared.saveLog(severity:.error,
    3.86 -                               entity: component, description: " \(err)", comment: "error")
    3.87 -        }
    3.88 -    }
    3.89 -
    3.90 -    static public func error(component: String, errorString: String, error: Error) {
    3.91 -        Log.shared.saveLog(severity:.error,
    3.92 -            entity: component, description: "\(errorString) \(error)", comment: "error")
    3.93 -    }
    3.94 -
    3.95 -    static public func error(component: String, errorString: String) {
    3.96 -        Log.shared.saveLog(severity:.error,
    3.97 -                           entity: component, description: errorString, comment: "error")
    3.98 -    }
    3.99 -
   3.100 -    public static func log(comp: String, mySelf: AnyObject, functionName: String) {
   3.101 -        let selfDesc = unsafeBitCast(mySelf, to: UnsafeRawPointer.self)
   3.102 -        Log.shared.info(component: comp, content: "\(functionName): \(selfDesc)")
   3.103 -    }
   3.104 -
   3.105 -    public func resume() {
   3.106 -        Log.shared.paused = false
   3.107 -    }
   3.108 -
   3.109 -    public func pause() {
   3.110 -        Log.shared.paused = true
   3.111 -        Log.shared.loggingQueue.cancelAllOperations()
   3.112 -    }
   3.113 -
   3.114 -    private let title = "pEpForiOS"
   3.115 -    private var logEnabled = true
   3.116 -    private var paused = false
   3.117 -
   3.118 -    private let loggingQueue: OperationQueue = {
   3.119 -        let createe = OperationQueue()
   3.120 -        createe.qualityOfService = .background
   3.121 -        createe.maxConcurrentOperationCount = 1
   3.122 -        return createe
   3.123 -    }()
   3.124 -
   3.125 -    private let internalLogger = ASLLogger()
   3.126 -
   3.127 -    /**
   3.128 -     Prints and/or saves a log entry.
   3.129 -     - Note: For a log to be printed, the entity must be contained in `allowedEntities`,
   3.130 -     or the severity must be noted in `allowedSeverities`.
   3.131 -     */
   3.132 -    private func saveLog(severity: LoggingSeverity,
   3.133 -                         entity: String,
   3.134 -                         description: String,
   3.135 -                         comment: String) {
   3.136 -        let allowedEntities = Set<String>(["CWIMAPStore", "ImapSync"])
   3.137 -        let allowedSeverities = Set<LoggingSeverity>([.error, .warning, .info])
   3.138 -
   3.139 -        if allowedSeverities.contains(severity) || allowedEntities.contains(entity) {
   3.140 -            internalLogger.saveLog(severity: severity,
   3.141 -                                   entity: entity,
   3.142 -                                   description: description,
   3.143 -                                   comment: comment)
   3.144 -        }
   3.145 -    }
   3.146 -}
   3.147 -
   3.148 -extension Log: MessageModelLogging {
   3.149 -    public func verbose(component: String, content: String) {
   3.150 -        Log.verbose(component: component, content: content)
   3.151 -    }
   3.152 -
   3.153 -    public func info(component: String, content: String) {
   3.154 -        Log.info(component: component, content: content)
   3.155 -    }
   3.156 -
   3.157 -    public func warn(component: String, content: String) {
   3.158 -        Log.warn(component: component, content: content)
   3.159 -    }
   3.160 -
   3.161 -    public func error(component: String, error: Error) {
   3.162 -        Log.error(component: component, error: error)
   3.163 -    }
   3.164 -
   3.165 -    public func error(component: String, errorString: String, error: Error) {
   3.166 -        Log.error(component: component, errorString: errorString, error: error)
   3.167 -    }
   3.168 -
   3.169 -    public func error(component: String, errorString: String) {
   3.170 -        Log.error(component: component, errorString: errorString)
   3.171 -    }
   3.172 -
   3.173 -    /// Logs component and error.
   3.174 -    ///
   3.175 -    /// - note: If (and only if) in DEBUG configuration, it also calls fatalError().
   3.176 -    ///
   3.177 -    /// - Parameters:
   3.178 -    ///   - component: caller information to log
   3.179 -    ///   - error: error to log
   3.180 -    public func errorAndCrash(component: String, error: Error) {
   3.181 -        Log.error(component: component, error: error)
   3.182 -        SystemUtils.crash("ERROR \(component): \(error.localizedDescription)")
   3.183 -    }
   3.184 -
   3.185 -    /// Logs component and error.
   3.186 -    ///
   3.187 -    /// - note: If (and only if) in DEBUG configuration, it also calls fatalError().
   3.188 -    ///
   3.189 -    /// - Parameters:
   3.190 -    ///   - component: caller information to log
   3.191 -    ///   - errorString: error information to log
   3.192 -    ///   - error: error to log
   3.193 -    public func errorAndCrash(component: String, errorString: String, error: Error) {
   3.194 -        Log.error(component: component, errorString: errorString, error: error)
   3.195 -        SystemUtils.crash("ERROR \(component): \(errorString): \(error.localizedDescription)")
   3.196 -    }
   3.197 -
   3.198 -    /// Logs component and error.
   3.199 -    ///
   3.200 -    /// - note: If (and only if) in DEBUG configuration, it also calls fatalError().
   3.201 -    ///
   3.202 -    /// - Parameters:
   3.203 -    ///   - component: caller information to log
   3.204 -    ///   - errorString: error information to log
   3.205 -    public func errorAndCrash(component: String, errorString: String) {
   3.206 -        Log.error(component: component, errorString: errorString)
   3.207 -        SystemUtils.crash("ERROR \(component): \(errorString)")
   3.208 -    }
   3.209 -}
     4.1 --- a/MessageModel/MessageModel/NetworkService/Util/Logger.swift	Thu Feb 21 13:42:30 2019 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,452 +0,0 @@
     4.4 -//
     4.5 -//  Logger.swift
     4.6 -//  pEp
     4.7 -//
     4.8 -//  Created by Dirk Zimmermann on 18.12.18.
     4.9 -//  Copyright © 2018 p≡p Security S.A. All rights reserved.
    4.10 -//
    4.11 -
    4.12 -import Foundation
    4.13 -import asl
    4.14 -import os.log
    4.15 -
    4.16 -/**
    4.17 - Thin layer over `os_log` or `asl_logger` where not available.
    4.18 - The fallback to asl is only in effect for iOS 9, and currently
    4.19 - doesn't appear anywhere visible on that platform.
    4.20 - */
    4.21 -public class Logger {
    4.22 -    /**
    4.23 -     Map `os_log` levels.
    4.24 -     */
    4.25 -    public enum Severity {
    4.26 -        /**
    4.27 -         - Note: Not persisted by default, but will be written in case of errors.
    4.28 -         */
    4.29 -        case info
    4.30 -
    4.31 -        /**
    4.32 -         - Note: Not persisted by default, but will be written in case of errors.
    4.33 -         */
    4.34 -        case debug
    4.35 -
    4.36 -        /**
    4.37 -         This is the lowest priority that gets written to disk by default.
    4.38 -         Used like WARN in this logger.
    4.39 -         */
    4.40 -        case `default`
    4.41 -
    4.42 -        case error
    4.43 -
    4.44 -        /**
    4.45 -         - Note: As this is referring to inter-process problems, I don't see a use-case
    4.46 -         for iOS.
    4.47 -         */
    4.48 -        case fault
    4.49 -
    4.50 -        @available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *)
    4.51 -        public func osLogType() -> OSLogType {
    4.52 -            switch self {
    4.53 -            case .info:
    4.54 -                return .info
    4.55 -            case .debug:
    4.56 -                return .debug
    4.57 -            case .default:
    4.58 -                return .default
    4.59 -            case .error:
    4.60 -                return .error
    4.61 -            case .fault:
    4.62 -                return .fault
    4.63 -            }
    4.64 -        }
    4.65 -
    4.66 -        /**
    4.67 -         Maps the internal criticality of a log  message into a subsystem of ASL levels.
    4.68 -
    4.69 -         ASL has the following:
    4.70 -         * ASL_LEVEL_EMERG
    4.71 -         * ASL_LEVEL_ALERT
    4.72 -         * ASL_LEVEL_CRIT
    4.73 -         * ASL_LEVEL_ERR
    4.74 -         * ASL_LEVEL_WARNING
    4.75 -         * ASL_LEVEL_NOTICE
    4.76 -         * ASL_LEVEL_INFO
    4.77 -         * ASL_LEVEL_DEBUG
    4.78 -         */
    4.79 -        public func aslLevelString() -> String {
    4.80 -            switch self {
    4.81 -            case .default:
    4.82 -                return "ASL_LEVEL_NOTICE"
    4.83 -            case .info:
    4.84 -                return "ASL_LEVEL_INFO"
    4.85 -            case .debug:
    4.86 -                return "ASL_LEVEL_DEBUG"
    4.87 -            case .error:
    4.88 -                return "ASL_LEVEL_ERR"
    4.89 -            case .fault:
    4.90 -                return "ASL_LEVEL_CRIT"
    4.91 -            }
    4.92 -        }
    4.93 -    }
    4.94 -
    4.95 -    public static let frontendLogger = Logger(category: "frontend")
    4.96 -    public static let backendLogger = Logger(category: "backend")
    4.97 -    public static let utilLogger = Logger(category: "util")
    4.98 -    public static let htmlParsingLogger = Logger(category: "htmlParsing")
    4.99 -    public static let modelLogger = Logger(category: "model")
   4.100 -    public static let appDelegateLogger = Logger(category: "appDelegate")
   4.101 -
   4.102 -    public init(subsystem: String = "security.pEp.app.iOS", category: String) {
   4.103 -        self.subsystem = subsystem
   4.104 -        self.category = category
   4.105 -        if #available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
   4.106 -            osLogger = OSLog(subsystem: subsystem, category: category)
   4.107 -        } else {
   4.108 -            osLogger = nil
   4.109 -        }
   4.110 -    }
   4.111 -
   4.112 -    /**
   4.113 -     Logs to default.
   4.114 -     */
   4.115 -    public func log(function: String = #function,
   4.116 -                    filePath: String = #file,
   4.117 -                    fileLine: Int = #line,
   4.118 -                    _ message: StaticString,
   4.119 -                    _ args: CVarArg...) {
   4.120 -        saveLog(message: message,
   4.121 -                severity: .default,
   4.122 -                function: function,
   4.123 -                filePath: filePath,
   4.124 -                fileLine: fileLine,
   4.125 -                args: args)
   4.126 -    }
   4.127 -
   4.128 -    /**
   4.129 -     os_log doesn't have a warn per se, but default is coming close.
   4.130 -     This is the same as log.
   4.131 -     */
   4.132 -    public func warn(function: String = #function,
   4.133 -                     filePath: String = #file,
   4.134 -                     fileLine: Int = #line,
   4.135 -                     _ message: StaticString,
   4.136 -                     _ args: CVarArg...) {
   4.137 -        saveLog(message: message,
   4.138 -                severity: .default,
   4.139 -                function: function,
   4.140 -                filePath: filePath,
   4.141 -                fileLine: fileLine,
   4.142 -                args: args)
   4.143 -    }
   4.144 -
   4.145 -    /**
   4.146 -     Logs to info.
   4.147 -     */
   4.148 -    public func info(function: String = #function,
   4.149 -                     filePath: String = #file,
   4.150 -                     fileLine: Int = #line,
   4.151 -                     _ message: StaticString,
   4.152 -                     _ args: CVarArg...) {
   4.153 -        saveLog(message: message,
   4.154 -                severity: .info,
   4.155 -                function: function,
   4.156 -                filePath: filePath,
   4.157 -                fileLine: fileLine,
   4.158 -                args: args)
   4.159 -    }
   4.160 -
   4.161 -    /**
   4.162 -     Logs to debug.
   4.163 -     */
   4.164 -    public func debug(function: String = #function,
   4.165 -                      filePath: String = #file,
   4.166 -                      fileLine: Int = #line,
   4.167 -                      _ message: StaticString,
   4.168 -                      _ args: CVarArg...) {
   4.169 -        saveLog(message: message,
   4.170 -                severity: .debug,
   4.171 -                function: function,
   4.172 -                filePath: filePath,
   4.173 -                fileLine: fileLine,
   4.174 -                args: args)
   4.175 -    }
   4.176 -
   4.177 -    /**
   4.178 -     Logs to error.
   4.179 -     */
   4.180 -    public func error(function: String = #function,
   4.181 -                      filePath: String = #file,
   4.182 -                      fileLine: Int = #line,
   4.183 -                      _ message: StaticString,
   4.184 -                      _ args: CVarArg...) {
   4.185 -        saveLog(message: message,
   4.186 -                severity: .error,
   4.187 -                function: function,
   4.188 -                filePath: filePath,
   4.189 -                fileLine: fileLine,
   4.190 -                args: args)
   4.191 -    }
   4.192 -
   4.193 -    /**
   4.194 -     Logs to fault.
   4.195 -     */
   4.196 -    public func fault(function: String = #function,
   4.197 -                      filePath: String = #file,
   4.198 -                      fileLine: Int = #line,
   4.199 -                      _ message: StaticString,
   4.200 -                      _ args: CVarArg...) {
   4.201 -        saveLog(message: message,
   4.202 -                severity: .fault,
   4.203 -                function: function,
   4.204 -                filePath: filePath,
   4.205 -                fileLine: fileLine,
   4.206 -                args: args)
   4.207 -    }
   4.208 -
   4.209 -    public func errorAndCrash(function: String = #function,
   4.210 -                              filePath: String = #file,
   4.211 -                              fileLine: Int = #line,
   4.212 -                              _ message: StaticString,
   4.213 -                              _ args: CVarArg...) {
   4.214 -        saveLog(message: message,
   4.215 -                severity: .fault,
   4.216 -                function: function,
   4.217 -                filePath: filePath,
   4.218 -                fileLine: fileLine,
   4.219 -                args: args)
   4.220 -
   4.221 -        // This will omit the arguments, but it's still matchable
   4.222 -        SystemUtils.crash("\(message)")
   4.223 -    }
   4.224 -
   4.225 -    /**
   4.226 -     Logs an error.
   4.227 -     */
   4.228 -    public func log(function: String = #function,
   4.229 -                    filePath: String = #file,
   4.230 -                    fileLine: Int = #line,
   4.231 -                    error: Error) {
   4.232 -        // Error is not supported by "%@", because it doesn't conform to CVArg
   4.233 -        // and CVArg is only meant for internal types.
   4.234 -        // An alternative would be to use localizedDescription(),
   4.235 -        // but if they are indeed localized you end up with international
   4.236 -        // log messages.
   4.237 -        // So we wrap it into an NSError which does suppord CVArg.
   4.238 -        let nsErr = NSError(domain: subsystem, code: 0, userInfo: [NSUnderlyingErrorKey: error])
   4.239 -
   4.240 -        saveLog(message: "%{public}@",
   4.241 -                severity: .default,
   4.242 -                function: function,
   4.243 -                filePath: filePath,
   4.244 -                fileLine: fileLine,
   4.245 -                args: [nsErr])
   4.246 -    }
   4.247 -
   4.248 -    /**
   4.249 -     Testing only. If you want to test the fallback to ASL logging you may have to call
   4.250 -     this, as all the logging is deferred to a serial queue.
   4.251 -     */
   4.252 -    public func testFlush() {
   4.253 -        if #available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
   4.254 -            // no sense on these versions
   4.255 -        } else {
   4.256 -            aslLogQueue.sync {
   4.257 -                // nothing
   4.258 -            }
   4.259 -        }
   4.260 -    }
   4.261 -
   4.262 -    /**
   4.263 -     Since this kind of logging is used so often in the codebase, it has its
   4.264 -     own method.
   4.265 -     */
   4.266 -    public func lostMySelf() {
   4.267 -        errorAndCrash("Lost MySelf")
   4.268 -    }
   4.269 -
   4.270 -    private let subsystem: String
   4.271 -    private let category: String
   4.272 -
   4.273 -    private let osLogger: Any?
   4.274 -
   4.275 -    private func saveLog(message: StaticString,
   4.276 -                         severity: Severity,
   4.277 -                         function: String = #function,
   4.278 -                         filePath: String = #file,
   4.279 -                         fileLine: Int = #line,
   4.280 -                         args: [CVarArg]) {
   4.281 -        if #available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
   4.282 -            osLog(message: message,
   4.283 -                  severity: severity,
   4.284 -                  function: function,
   4.285 -                  filePath: filePath,
   4.286 -                  fileLine: fileLine,
   4.287 -                  args: args)
   4.288 -        } else {
   4.289 -            aslLog(message: message,
   4.290 -                   severity: severity,
   4.291 -                   function: function,
   4.292 -                   filePath: filePath,
   4.293 -                   fileLine: fileLine,
   4.294 -                   args: args)
   4.295 -        }
   4.296 -    }
   4.297 -
   4.298 -    /**
   4.299 -     - Note: If the number of arguments to the format string exceeds 10,
   4.300 -     the logging doesn't work correctly. Can be easily fixed though, if really needed.
   4.301 -     */
   4.302 -    @available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *)
   4.303 -    private func osLog(message: StaticString,
   4.304 -                       severity: Severity,
   4.305 -                       function: String = #function,
   4.306 -                       filePath: String = #file,
   4.307 -                       fileLine: Int = #line,
   4.308 -                       args: [CVarArg]) {
   4.309 -        let theLog = osLogger as! OSLog
   4.310 -        let theType = severity.osLogType()
   4.311 -
   4.312 -        // I haven't found a way of injecting `function` etc. into the original message for
   4.313 -        // just one call to `os_log`, so the 'position' is logged on a separate line.
   4.314 -        os_log("%@:%d %@:",
   4.315 -               log: theLog,
   4.316 -               type: theType,
   4.317 -               filePath,
   4.318 -               fileLine,
   4.319 -               function)
   4.320 -
   4.321 -        // We have to expand the array of arguments into positional ones.
   4.322 -        // There is no attempt of trying to format the string on our side
   4.323 -        // in order to make use of `os_log`'s fast 'offline' formatting
   4.324 -        // (that is, the work is delayed until actual log display).
   4.325 -        switch args.count {
   4.326 -        case 0:
   4.327 -            os_log(message,
   4.328 -                   log: theLog,
   4.329 -                   type: theType)
   4.330 -        case 1:
   4.331 -            os_log(message,
   4.332 -                   log: theLog,
   4.333 -                   type: theType,
   4.334 -                   args[0])
   4.335 -        case 2:
   4.336 -            os_log(message,
   4.337 -                   log: theLog,
   4.338 -                   type: theType,
   4.339 -                   args[0], args[1])
   4.340 -        case 3:
   4.341 -            os_log(message,
   4.342 -                   log: theLog,
   4.343 -                   type: theType,
   4.344 -                   args[0], args[1], args[2])
   4.345 -        case 4:
   4.346 -            os_log(message,
   4.347 -                   log: theLog,
   4.348 -                   type: theType,
   4.349 -                   args[0], args[1], args[2], args[3])
   4.350 -        case 5:
   4.351 -            os_log(message,
   4.352 -                   log: theLog,
   4.353 -                   type: theType,
   4.354 -                   args[0], args[1], args[2], args[3], args[4])
   4.355 -        case 6:
   4.356 -            os_log(message,
   4.357 -                   log: theLog,
   4.358 -                   type: theType,
   4.359 -                   args[0], args[1], args[2], args[3], args[4], args[5])
   4.360 -        case 7:
   4.361 -            os_log(message,
   4.362 -                   log: theLog,
   4.363 -                   type: theType,
   4.364 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6])
   4.365 -        case 8:
   4.366 -            os_log(message,
   4.367 -                   log: theLog,
   4.368 -                   type: theType,
   4.369 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])
   4.370 -        case 9:
   4.371 -            os_log(message,
   4.372 -                   log: theLog,
   4.373 -                   type: theType,
   4.374 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
   4.375 -                   args[8])
   4.376 -        case 10:
   4.377 -            os_log(message,
   4.378 -                   log: theLog,
   4.379 -                   type: theType,
   4.380 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
   4.381 -                   args[8], args[9])
   4.382 -        default:
   4.383 -            os_log("Using more than 10 parameters",
   4.384 -                   log: theLog,
   4.385 -                   type: .error)
   4.386 -            os_log(message,
   4.387 -                   log: theLog,
   4.388 -                   type: theType,
   4.389 -                   args)
   4.390 -        }
   4.391 -    }
   4.392 -
   4.393 -    private func aslLog(message: StaticString,
   4.394 -                        severity: Severity,
   4.395 -                        function: String = #function,
   4.396 -                        filePath: String = #file,
   4.397 -                        fileLine: Int = #line,
   4.398 -                        args: [CVarArg]) {
   4.399 -        aslLogQueue.async { [weak self] in
   4.400 -            if let theSelf = self {
   4.401 -                let logMessage = asl_new(UInt32(ASL_TYPE_MSG))
   4.402 -
   4.403 -                theSelf.checkASLSuccess(asl_set(logMessage, ASL_KEY_SENDER, theSelf.subsystem))
   4.404 -
   4.405 -                theSelf.checkASLSuccess(asl_set(logMessage, ASL_KEY_FACILITY, theSelf.category))
   4.406 -
   4.407 -                theSelf.checkASLSuccess(asl_set(
   4.408 -                    logMessage,
   4.409 -                    ASL_KEY_MSG,
   4.410 -                    "\(filePath):\(fileLine) \(function): \(message) \(args)"))
   4.411 -
   4.412 -                theSelf.checkASLSuccess(asl_set(logMessage, ASL_KEY_LEVEL, "ASL_LEVEL_ERROR"))
   4.413 -
   4.414 -                let nowDate = Date()
   4.415 -                let dateString = "\(Int(nowDate.timeIntervalSince1970))"
   4.416 -                theSelf.checkASLSuccess(asl_set(logMessage, ASL_KEY_TIME, dateString))
   4.417 -
   4.418 -                theSelf.checkASLSuccess(asl_set(logMessage, ASL_KEY_READ_UID, "-1"))
   4.419 -
   4.420 -                theSelf.checkASLSuccess(asl_send(theSelf.consoleLogger(), logMessage))
   4.421 -
   4.422 -                asl_free(logMessage)
   4.423 -            }
   4.424 -        }
   4.425 -    }
   4.426 -
   4.427 -    private var consoleClient: aslclient?
   4.428 -
   4.429 -    private lazy var aslLogQueue = DispatchQueue(label: "security.pEp.asl.log")
   4.430 -
   4.431 -    private let sender = "security.pEp.app.iOS"
   4.432 -
   4.433 -    private func createConsoleLogger() -> asl_object_t {
   4.434 -        return asl_open(self.sender, subsystem, 0)
   4.435 -    }
   4.436 -
   4.437 -    private func consoleLogger() -> aslclient? {
   4.438 -        if consoleClient == nil {
   4.439 -            consoleClient = createConsoleLogger()
   4.440 -        }
   4.441 -        return consoleClient
   4.442 -    }
   4.443 -
   4.444 -    deinit {
   4.445 -        if consoleClient != nil {
   4.446 -            asl_free(consoleClient)
   4.447 -        }
   4.448 -    }
   4.449 -
   4.450 -    private func checkASLSuccess(_ result: Int32, comment: String = "no comment") {
   4.451 -        if result != 0 {
   4.452 -            print("*** error: \(comment)")
   4.453 -        }
   4.454 -    }
   4.455 -}