IOS-1540 Interpolationg logging strings ourselves. IOS-1540_GOOD
authorDirk Zimmermann <dz@pep.security>
Tue, 11 Jun 2019 16:28:31 +0200
branchIOS-1540_GOOD
changeset 90186e79d0343779
parent 9017 fa60d7acc4c8
child 9019 bb44b2d74f50
IOS-1540 Interpolationg logging strings ourselves.
Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Logger.swift
     1.1 --- a/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Logger.swift	Tue Jun 11 16:28:31 2019 +0200
     1.2 +++ b/Submodules/pEpIOSToolbox/pEpIOSToolbox/Other/Logger.swift	Tue Jun 11 16:28:31 2019 +0200
     1.3 @@ -271,84 +271,15 @@
     1.4          let theLog = osLogger as! OSLog
     1.5          let theType = severity.osLogType()
     1.6  
     1.7 -        os_log("%{public}@:%d %{public}@: %{public}@ (%{public}@)",
     1.8 +        let formatString = "\(message)".replacingOccurrences(of: "%{public}", with: "%")
     1.9 +        let ourString = String(format: formatString, arguments: args)
    1.10 +
    1.11 +        os_log("%{public}@:%d %{public}@: %{public}@",
    1.12                 log: theLog,
    1.13                 type: theType,
    1.14                 filePath,
    1.15                 fileLine,
    1.16                 function,
    1.17 -               "\(message)",
    1.18 -               args)
    1.19 -
    1.20 -        // We have to expand the array of arguments into positional ones.
    1.21 -        // There is no attempt of trying to format the string on our side
    1.22 -        // in order to make use of `os_log`'s fast 'offline' formatting
    1.23 -        // (that is, the work is delayed until actual log display).
    1.24 -        switch args.count {
    1.25 -        case 0:
    1.26 -            os_log(message,
    1.27 -                   log: theLog,
    1.28 -                   type: theType)
    1.29 -        case 1:
    1.30 -            os_log(message,
    1.31 -                   log: theLog,
    1.32 -                   type: theType,
    1.33 -                   args[0])
    1.34 -        case 2:
    1.35 -            os_log(message,
    1.36 -                   log: theLog,
    1.37 -                   type: theType,
    1.38 -                   args[0], args[1])
    1.39 -        case 3:
    1.40 -            os_log(message,
    1.41 -                   log: theLog,
    1.42 -                   type: theType,
    1.43 -                   args[0], args[1], args[2])
    1.44 -        case 4:
    1.45 -            os_log(message,
    1.46 -                   log: theLog,
    1.47 -                   type: theType,
    1.48 -                   args[0], args[1], args[2], args[3])
    1.49 -        case 5:
    1.50 -            os_log(message,
    1.51 -                   log: theLog,
    1.52 -                   type: theType,
    1.53 -                   args[0], args[1], args[2], args[3], args[4])
    1.54 -        case 6:
    1.55 -            os_log(message,
    1.56 -                   log: theLog,
    1.57 -                   type: theType,
    1.58 -                   args[0], args[1], args[2], args[3], args[4], args[5])
    1.59 -        case 7:
    1.60 -            os_log(message,
    1.61 -                   log: theLog,
    1.62 -                   type: theType,
    1.63 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6])
    1.64 -        case 8:
    1.65 -            os_log(message,
    1.66 -                   log: theLog,
    1.67 -                   type: theType,
    1.68 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])
    1.69 -        case 9:
    1.70 -            os_log(message,
    1.71 -                   log: theLog,
    1.72 -                   type: theType,
    1.73 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
    1.74 -                   args[8])
    1.75 -        case 10:
    1.76 -            os_log(message,
    1.77 -                   log: theLog,
    1.78 -                   type: theType,
    1.79 -                   args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7],
    1.80 -                   args[8], args[9])
    1.81 -        default:
    1.82 -            os_log("Using more than 10 parameters",
    1.83 -                   log: theLog,
    1.84 -                   type: .error)
    1.85 -            os_log(message,
    1.86 -                   log: theLog,
    1.87 -                   type: theType,
    1.88 -                   args)
    1.89 -        }
    1.90 +               ourString)
    1.91      }
    1.92  }