os_log does not log Strings even if log format set to %{public}s.

Originator:volodymyr.gorlov
Number:rdar://28599032 Date Originated:04-Oct-2016
Status:Open Resolved:
Product:macOS SDK Product Version:10.12 (16A323)
Classification: Reproducible:100%
 
Summary:
Neither Xcode console, not Console.app shows log entries in which static or dynamic strings as arguments was used.

Same functionality manually bridged into Swift from ObjC code working as expected.

Steps to Reproduce:
Write and execute the following code:

      print("→ Swift")

      os_log("Message: %{public}s", log: SelfClass.log, type: .fault, "Swift: Test 1")
      os_log("Message: %{public}s", log: SelfClass.log, type: .fault, StaticString(stringLiteral: "Swift: Test 2").utf8Start)
      os_log("Message: %{public}s", log: SelfClass.log, type: .fault, unsafeBitCast(StaticString(stringLiteral: "Swift: Test 3").utf8Start, to: UnsafePointer<Int8>.self))

      print("→ ObjC")

      log_private(SelfClass.log, .fault, "ObjC: Test \(1)")
      log_public(SelfClass.log, .fault, "ObjC: Test \(1)")
      log_private(SelfClass.log, .fault, #file)
      log_public(SelfClass.log, .fault, #file)
      print("→ ObjC")

      log_private(SelfClass.log, .fault, "ObjC: Test \(1)")
      log_public(SelfClass.log, .fault, "ObjC: Test \(1)")
      log_private(SelfClass.log, .fault, #file)
      log_public(SelfClass.log, .fault, #file)

Where log_private and log_public are functions bridged from ObjC:

 void log_private(os_log_t log, os_log_type_t type, NSString * message) {
   os_log_with_type(log, type, "%s", [message cStringUsingEncoding:NSUTF8StringEncoding]);
}

void log_public(os_log_t log, os_log_type_t type, NSString * message) {
   os_log_with_type(log, type, "%{public}s", [message cStringUsingEncoding:NSUTF8StringEncoding]);
}

Expected Results:
Xcode console and Console.app should show:

→ Swift
[REDACTED] Swift: Test 1
[REDACTED] Swift: Test 2
[REDACTED] Swift: Test 3
→ ObjC
[REDACTED] <private>
[REDACTED] ObjC: Test 1
[REDACTED] <private>
[REDACTED] /[REDACTED]/ViewController.swift

Actual Results:
Xcode console and Console.app shows:

→ Swift
→ ObjC
[REDACTED] <private>
[REDACTED] ObjC: Test 1
[REDACTED] <private>
[REDACTED] /[REDACTED]/ViewController.swift

Version:
Xcode: 8.0 (8A218a)
macOS: 10.12 (16A323)

Comments

Behaves correctly in macOS 10.12.1 and iOS 10.1

Instead of "%{public}s" format "%{public}@" has to be used in Swift.

Example:

  os_log("Message: %{public}@", log: SelfClass.log, type: .fault, "Swift: Test 1")
  os_log("Message: %{public}@", log: SelfClass.log, type: .fault, #file)

Output:

  [REDACTED] Message: Swift: Test 1
  [REDACTED] Message: [REDACTED]/ViewController.swift
By volodymyr.gorlov at Oct. 25, 2016, 4:12 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!