How to verify that truncation occurs after 1024 bytes in os_log?

I was using os_log in my code and in header of oslog, it has been mentioned that there is physical cap of 1024 bytes per log line for dynamic content. So I was looking for a work around but before that I am not able see the truncation when I tried creating this issue.

let baseString = String(repeating: "a", count: 1020)
let criticalMarker = "LAST_5_BYTES"
let testString = baseString + criticalMarker // 1020 + 12 = 1032 bytes
os_log("LONG_STRING: %@", testString)

I used this as a sample code to check the truncation but in Xcode debugger it logs all the 1020 bytes and the last 12 bytes as well. I even checked the console and there also it was logging all the bytes. Can anyone help me with this as to what I am missing here?

Answered by DTS Engineer in 827633022
Written by Vesemir in 775779021
Can anyone help me with this as to what I am missing here?

The key point you’re missing here is that Xcode has a custom mechanism for capturing logs that’s different from the standard path used by the system log. That mechanism doesn’t truncate. If you want to see truncation in action, monitor the system log using Console [1].

Oh, and this custom mechanism is why Xcode is able to capture private data regardless of how your log point is annotated.

The above assumes you’re using Xcode’s new log integration, that is, Xcode 15 or later, targeting iOS 17 or later. There’s a different story if you’re running older stuff.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Normally I’d suggest that you run your app from the Home screen, rather than under the debugger, but in this case that won’t matter. Given how this is implemented, the truncation happens regardless of whether you have Xcode attached or not.

I am using this for an iOS app and using an iPhone to run the code.

Written by Vesemir in 775779021
Can anyone help me with this as to what I am missing here?

The key point you’re missing here is that Xcode has a custom mechanism for capturing logs that’s different from the standard path used by the system log. That mechanism doesn’t truncate. If you want to see truncation in action, monitor the system log using Console [1].

Oh, and this custom mechanism is why Xcode is able to capture private data regardless of how your log point is annotated.

The above assumes you’re using Xcode’s new log integration, that is, Xcode 15 or later, targeting iOS 17 or later. There’s a different story if you’re running older stuff.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Normally I’d suggest that you run your app from the Home screen, rather than under the debugger, but in this case that won’t matter. Given how this is implemented, the truncation happens regardless of whether you have Xcode attached or not.

How to verify that truncation occurs after 1024 bytes in os_log?
 
 
Q