IOS-1467 toolbox user new Log instead of Logger IOS-1467
authorAlejandro Gelos <agp@pep.security>
Mon, 15 Apr 2019 16:04:43 +0200
branchIOS-1467
changeset 8235c24dc73d5185
parent 8234 17dbcc19dd8d
child 8448 579e8e6a5052
IOS-1467 toolbox user new Log instead of Logger
Submodules/pEpIOSToolbox/pEpIOSToolbox/Modules/Log.swift
Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/SortedSet.swift
subModules/pEpIOSToolbox/pEpIOSToolbox.xcodeproj/project.pbxproj
subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/Data+Extensions.swift
subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/String+Extensions.swift
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Submodules/pEpIOSToolbox/pEpIOSToolbox/Modules/Log.swift	Mon Apr 15 16:04:43 2019 +0200
     1.3 @@ -0,0 +1,17 @@
     1.4 +//
     1.5 +//  Log.swift
     1.6 +//  pEpIOSToolbox
     1.7 +//
     1.8 +//  Created by Alejandro Gelos on 15/04/2019.
     1.9 +//  Copyright © 2019 pEp Security SA. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +import Foundation
    1.13 +
    1.14 +/// Shared instance of logger.
    1.15 +class Log {
    1.16 +    static let shared = Logger(subsystem: "security.pEp.MessageModel", category: "MessageModule")
    1.17 +
    1.18 +    /// Init is forbidden. Singleton...
    1.19 +    private init() {}
    1.20 +}
     2.1 --- a/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/SortedSet.swift	Mon Apr 15 14:29:14 2019 +0200
     2.2 +++ b/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/SortedSet.swift	Mon Apr 15 16:04:43 2019 +0200
     2.3 @@ -51,7 +51,7 @@
     2.4          defer { objc_sync_exit(self) }
     2.5  
     2.6          guard isValidIndex(index) else {
     2.7 -            Logger.frontendLogger.errorAndCrash("Index out of range")
     2.8 +            Log.shared.errorAndCrash("Index out of range")
     2.9              return
    2.10          }
    2.11          set.removeObject(at: index)
    2.12 @@ -62,7 +62,7 @@
    2.13          defer { objc_sync_exit(self) }
    2.14  
    2.15          guard isValidIndex(index) else {
    2.16 -            Logger.frontendLogger.errorAndCrash("Index out of range")
    2.17 +            Log.shared.errorAndCrash("Index out of range")
    2.18              return
    2.19          }
    2.20          set.replaceObject(at: index, with: object)
    2.21 @@ -73,7 +73,7 @@
    2.22          defer { objc_sync_exit(self) }
    2.23  
    2.24          guard isValidIndex(index) else {
    2.25 -            Logger.frontendLogger.errorAndCrash("Index out of range")
    2.26 +            Log.shared.errorAndCrash("Index out of range")
    2.27              return nil
    2.28          }
    2.29  
    2.30 @@ -101,7 +101,7 @@
    2.31  
    2.32          for i in 0..<set.count {
    2.33              guard let testee = set.object(at: i) as? T else {
    2.34 -                Logger.frontendLogger.errorAndCrash("error casting")
    2.35 +                Log.shared.errorAndCrash("error casting")
    2.36                  return NSNotFound
    2.37              }
    2.38              if testee == object {
    2.39 @@ -187,7 +187,7 @@
    2.40          set.sort { (first: Any, second: Any) -> ComparisonResult in
    2.41              guard let firstT = first as? T,
    2.42                  let secondT = second as? T else {
    2.43 -                    Logger.frontendLogger.errorAndCrash("Error casting.")
    2.44 +                    Log.shared.errorAndCrash("Error casting.")
    2.45                      return .orderedSame
    2.46              }
    2.47              return sortBlock(firstT, secondT)
    2.48 @@ -197,7 +197,7 @@
    2.49      private func indexOfObjectIfInserted(obj: T) -> Int {
    2.50          for i in 0..<set.count {
    2.51              guard let testee = set.object(at: i) as? T else {
    2.52 -                Logger.frontendLogger.errorAndCrash("Error casing")
    2.53 +                Log.shared.errorAndCrash("Error casing")
    2.54                  return 0
    2.55              }
    2.56              if set.count == 0 {
     3.1 --- a/subModules/pEpIOSToolbox/pEpIOSToolbox.xcodeproj/project.pbxproj	Mon Apr 15 14:29:14 2019 +0200
     3.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox.xcodeproj/project.pbxproj	Mon Apr 15 16:04:43 2019 +0200
     3.3 @@ -14,6 +14,7 @@
     3.4  		37904565223FA486006DAB3B /* ReachabilityProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37904561223FA486006DAB3B /* ReachabilityProtocol.swift */; };
     3.5  		37904569223FA52B006DAB3B /* NetworkReachibilityMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37904567223FA52B006DAB3B /* NetworkReachibilityMock.swift */; };
     3.6  		3790456A223FA52B006DAB3B /* ReachabilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37904568223FA52B006DAB3B /* ReachabilityTests.swift */; };
     3.7 +		37C3C0E92264BFB7003E290C /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37C3C0E82264BFB7003E290C /* Log.swift */; };
     3.8  		435F5129221FF9D7006EB11F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 435F5128221FF9D7006EB11F /* Constants.swift */; };
     3.9  		B70A3A5522005BD400EDCE61 /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B70A3A5422005BD400EDCE61 /* Date+Extension.swift */; };
    3.10  		B70A3A5722005BE300EDCE61 /* NSRegularExpression+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B70A3A5622005BE300EDCE61 /* NSRegularExpression+Extension.swift */; };
    3.11 @@ -62,6 +63,7 @@
    3.12  		37904561223FA486006DAB3B /* ReachabilityProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReachabilityProtocol.swift; sourceTree = "<group>"; };
    3.13  		37904567223FA52B006DAB3B /* NetworkReachibilityMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkReachibilityMock.swift; sourceTree = "<group>"; };
    3.14  		37904568223FA52B006DAB3B /* ReachabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReachabilityTests.swift; sourceTree = "<group>"; };
    3.15 +		37C3C0E82264BFB7003E290C /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Log.swift; path = ../../../../Submodules/pEpIOSToolbox/pEpIOSToolbox/Modules/Log.swift; sourceTree = "<group>"; };
    3.16  		435F5128221FF9D7006EB11F /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Constants.swift; path = ../../../../Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Constants.swift; sourceTree = "<group>"; };
    3.17  		B70A3A5422005BD400EDCE61 /* Date+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Date+Extension.swift"; sourceTree = "<group>"; };
    3.18  		B70A3A5622005BE300EDCE61 /* NSRegularExpression+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSRegularExpression+Extension.swift"; sourceTree = "<group>"; };
    3.19 @@ -165,6 +167,14 @@
    3.20  			path = ReachabilityUtilsTest;
    3.21  			sourceTree = "<group>";
    3.22  		};
    3.23 +		37C3C0E72264BF96003E290C /* Modules */ = {
    3.24 +			isa = PBXGroup;
    3.25 +			children = (
    3.26 +				37C3C0E82264BFB7003E290C /* Log.swift */,
    3.27 +			);
    3.28 +			path = Modules;
    3.29 +			sourceTree = "<group>";
    3.30 +		};
    3.31  		B70A3A5222005A7600EDCE61 /* Foundation */ = {
    3.32  			isa = PBXGroup;
    3.33  			children = (
    3.34 @@ -218,6 +228,7 @@
    3.35  		B7911EB621F7358500D7F66F /* pEpIOSToolbox */ = {
    3.36  			isa = PBXGroup;
    3.37  			children = (
    3.38 +				37C3C0E72264BF96003E290C /* Modules */,
    3.39  				B70A3A5222005A7600EDCE61 /* Foundation */,
    3.40  				B70A3A5322005B9600EDCE61 /* UIKit */,
    3.41  				B7DB7FEC221B086A003968DA /* Other */,
    3.42 @@ -390,6 +401,7 @@
    3.43  				B7DB7F5022130DE9003968DA /* Weak.swift in Sources */,
    3.44  				37904564223FA486006DAB3B /* NetworkReachability.swift in Sources */,
    3.45  				B7A46C52220C732E0027CCB5 /* Data+Extensions.swift in Sources */,
    3.46 +				37C3C0E92264BFB7003E290C /* Log.swift in Sources */,
    3.47  				B7465DE32211C890008A1708 /* CGImageSource+Extension.swift in Sources */,
    3.48  				B7465DE12211C6E9008A1708 /* UIImage+GIF.swift in Sources */,
    3.49  				B70A3A5522005BD400EDCE61 /* Date+Extension.swift in Sources */,
     4.1 --- a/subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/Data+Extensions.swift	Mon Apr 15 14:29:14 2019 +0200
     4.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/Data+Extensions.swift	Mon Apr 15 16:04:43 2019 +0200
     4.3 @@ -30,8 +30,7 @@
     4.4          do {
     4.5              try write(to: url)
     4.6          } catch {
     4.7 -            
     4.8 -            Logger.utilLogger.error("Could not save to %{public}@", url.absoluteString)
     4.9 +            Log.shared.error("Could not save to %{public}@", url.absoluteString)
    4.10          }
    4.11      }
    4.12  
    4.13 @@ -41,7 +40,7 @@
    4.14                  withJSONObject: self, options: .prettyPrinted)
    4.15              jsonData.debugSave(basePath: basePath, fileName: fileName, ext: ext)
    4.16          } catch let err {
    4.17 -            Logger.utilLogger.error("%{public}@", err.localizedDescription)
    4.18 +            Log.shared.error("%{public}@", err.localizedDescription)
    4.19          }
    4.20      }
    4.21  }
     5.1 --- a/subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/String+Extensions.swift	Mon Apr 15 14:29:14 2019 +0200
     5.2 +++ b/subModules/pEpIOSToolbox/pEpIOSToolbox/Foundation/String+Extensions.swift	Mon Apr 15 16:04:43 2019 +0200
     5.3 @@ -152,7 +152,7 @@
     5.4                                                      range: range,
     5.5                                                      withTemplate: replacee)
     5.6          } catch {
     5.7 -            Logger.utilLogger.errorAndCrash("Catched!")
     5.8 +            Log.shared.errorAndCrash("Catched!")
     5.9              return result
    5.10          }
    5.11          return result
    5.12 @@ -178,7 +178,7 @@
    5.13              let matches = regex.matches(in: self, options: [], range: wholeRange())
    5.14              return matches.count > 0
    5.15          } catch {
    5.16 -            Logger.utilLogger.errorAndCrash("%{public}@", error.localizedDescription)
    5.17 +            Log.shared.errorAndCrash("%{public}@", error.localizedDescription)
    5.18          }
    5.19          return false
    5.20      }
    5.21 @@ -209,7 +209,7 @@
    5.22                  }
    5.23              }
    5.24          } catch {
    5.25 -            Logger.utilLogger.errorAndCrash("%{public}@",
    5.26 +            Log.shared.errorAndCrash("%{public}@",
    5.27                                                          error.localizedDescription)
    5.28          }
    5.29          return self
    5.30 @@ -233,7 +233,7 @@
    5.31                  }
    5.32              }
    5.33          } catch {
    5.34 -            Logger.utilLogger.errorAndCrash("%{public}@",
    5.35 +            Log.shared.errorAndCrash("%{public}@",
    5.36                                                          error.localizedDescription)
    5.37          }
    5.38          return self