Using os_log to log function arguments, or other dynamic data

前端 未结 5 1517
一向
一向 2021-01-03 00:24

I\'m trying to log function arguments into os_log like this:

func foo(x: String, y: [String:String]) {
    //...
    os_log(\"foo: \\(x) \\(y.de         


        
5条回答
  •  感情败类
    2021-01-03 00:44

    The macOS 11 Big Sur Release Notes state that os_log can now be passed Swift string interpolation:

    https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11-beta-release-notes

    Logging

    New Features

    • New APIs are available for using os_log from Swift as part of the os framework:

      • A new type Logger can be instantiated using a subsystem and category and provides methods for logging at different levels ( debug(_:) , error(_:) , fault(_:) ).

      • The Logger APIs support specifying most formatting and privacy options supported by legacy os_log APIs.

      • The new APIs provide significant performance improvements over the legacy APIs.

      • You can now pass Swift string interpolation to the os_log function.

    Note: The new APIs can't be back deployed; however, the existing os_log API remains available for back deployment. (22539144)

提交回复
热议问题