为什么Xcode 8(iOS 10)在控制台中打印[LogMessageLogging] <private>

时间:2016-07-13 06:59:47

标签: ios xcode xcode8 ios10

当我调用地图视图时,为什么Xcode 8(iOS 10)在控制台中打印[LogMessageLogging] <private>

任何人都可以提出一些建议吗?

"<private>" printed to console

3 个答案:

答案 0 :(得分:8)

  

隐私

     

统一日志记录系统将动态字符串和复杂动态对象视为私有,并且不会自动收集它们。为确保用户的隐私,建议日志消息严格包含静态字符串数字。在需要捕获动态字符串的情况下,您可以明确使用关键字 public 将字符串声明为public。例如,<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript"> var r = prompt ("how many rows ?"); var c = prompt ("how many columns ?"); var red = prompt ("how red ?"); var green = prompt ("how green ?"); var blue = prompt ("how blue ?"); document.write('<table style="width:100%" bgcolor="'+red+''+green+''+blue+'">'); for(var r = i; i > -1; i--){ document.write('<tr>'); for(var c = i; i > -1; i--){ document.write('<th></th>'); }; document.write('</tr>'); }; document.write('</table>'); </script> </head> <body> </body> </html>

示例(ObjC):

%{public}s

示例(Swift):

目前在Swift(https://openradar.appspot.com/radar?id=6068967584038912)中记录字符串似乎已被破坏,因此我们需要手动将C函数桥接到Swift:

更新01 。雷达28599032是修复版,不适用于Xcode 10。

os_log_t log = os_log_create("com.example.my-subsystem", "test");

const char *staticString = "I am static string!";
const char *dynamicString = [[NSString stringWithFormat:@"I am %@!", @"dynamic string"]
                             cStringUsingEncoding:NSUTF8StringEncoding];

os_log(log, "Message: %s", staticString);
os_log(log, "Message: %s", dynamicString);
os_log(log, "Message: %{public}s", dynamicString);

// Output
// [test] Message: I am static string!
// [test] Message: <private>
// [test] Message: I am dynamic string!

答案 1 :(得分:1)

这是MacOS 10.12(Sierra)的新功能,统一logging system

  

实现管理日志记录行为和持久性的全局设置,同时通过日志命令行工具和使用自定义日志记录配置配置文件在调试期间提供细粒度控制。

基本上,您可以通过os_log指定要在哪个级别记录内容,这样可以使Console更有用。关闭私人&#39;设置您正在使用的项目,在终端中输入:

$ sudo log config --mode "level:debug" --subsystem com.your_company.your_subsystem_name

Customizing Logging Behavior While Debugging

的更多信息

更新:

正如@SunilChauhan指出的那样,上面的链接现在已经破了。搜索日志记录和NSLog可以获得很多结果,没有任何相关性。但是,搜索原始链接中的数字会将我带到一个名为Logging: Using the os_log APIs的示例项目,该项目承诺:

  

演示如何在C,Objective-C和Swift中使用os_log API。它们显示了故障和错误之间的区别,以及它们可以接受的情况。请参阅这些示例以了解如何使用自定义日志类别,如何确定要使用的日志级别以及如何实时查看日志。

我现在没有时间尝试这个项目,我希望它对某人有用。

答案 2 :(得分:0)

另一个答案中显示的per-bundle-id控制台命令对我不起作用。

这有效:

sudo log config --mode "private_data:on"

https://superuser.com/questions/1311578/in-console-app-how-can-i-reveal-to-what-private-tags-are-actually-referring