Passing variadic args in Swift 4 for os_log
Your idea contains a couple of issues:
Apple discourages the wrapping of
os_log
in another function, doing so results in losing some nice feature of the Unified Logging System, like having the code line, library, file etc in the logs automagically.As soon as
args
is passed to your own function that type pass from cvargs to [String] and in theory it's impossible re-build the list of args, you can find an amazing explanation in the first answer here: Why does wrapping os_log() cause doubles to not be logged correctly?
I also haven't found solution yet so made this silly hack:
switch args.count {
case 0:
os_log(message, log: log!, type: type)
case 1:
os_log(message, log: log!, type: type, args[0])
case 2:
os_log(message, log: log!, type: type, args[0], args[1])
case 3:
os_log(message, log: log!, type: type, args[0], args[1], args[2])
default:
os_log(message, log: log!, type: type, args)
}