为什么Xcode 8(iOS 10)打印[LogMessageLogging]< private>在控制台中 [英] Why the Xcode 8 (iOS 10) print [LogMessageLogging] <private> in console

查看:51
本文介绍了为什么Xcode 8(iOS 10)打印[LogMessageLogging]< private>在控制台中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why does Xcode 8 (iOS 10) print [LogMessageLogging] <private> in the console, when I call the map view?

有人可以提出建议吗?

推荐答案

隐私

统一日志记录系统将动态字符串和复杂的动态对象视为私有,并且不会自动收集它们.为了确保用户的隐私,建议日志消息严格由静态字符串数字组成.在需要捕获动态字符串的情况下,可以使用关键字 public 明确地将字符串声明为public.例如,%{public} s .

The unified logging system considers dynamic strings and complex dynamic objects to be private, and does not collect them automatically. To ensure the privacy of users, it is recommended that log messages consist strictly of static strings and numbers. In situations where it is necessary to capture a dynamic string, you may explicitly declare the string public using the keyword public. For example, %{public}s.

  • 来源: https://developer.apple.com/reference/os/1891852-记录
  • WWDC视频: https://developer.apple.com/视频/播放/wwdc2016/721/?time = 714
  • 示例(ObjC):

    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!
    


    示例(快速):


    Example (Swift):

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

    At the moment logging strings seems broken in Swift (https://openradar.appspot.com/radar?id=6068967584038912), so we need manually bridge C functions to Swift:

    UPDATE 01 .雷达28599032已修复,不适用于Xcode 10.

    UPDATE 01. Radar 28599032 is fixes and not applicable for Xcode 10.

    // File: os_log_rdar28599032.h
    #import <Foundation/Foundation.h>
    #import <os/log.h>
    
    void log_private(os_log_t, os_log_type_t, NSString *);
    void log_public(os_log_t, os_log_type_t, NSString *);
    
    
    // File: os_log_rdar28599032.m
    #import "os_log_rdar28599032.h"
    
    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]);
    }
    
    
    // File: ViewController.swift
    import Cocoa
    import os.log
    import os.activity
    
    class ViewController: NSViewController {
    
       static let log = OSLog(subsystem: "com.example.my-subsystem", category: "test")
       typealias SelfClass = ViewController
    
       override func viewDidLoad() {
          super.viewDidLoad()
          log_private(SelfClass.log, .fault, "I am dynamic \("string")!")
          log_public(SelfClass.log, .fault, "I am dynamic \("string")!")
          log_private(SelfClass.log, .fault, #file)
          log_public(SelfClass.log, .fault, #file)
       }
    
    }
    
    // Output
    // [test] <private>
    // [test] I am dynamic string!
    // [test] <private>
    // [test] /[REDACTED]/ViewController.swift
    

    这篇关于为什么Xcode 8(iOS 10)打印[LogMessageLogging]&lt; private&gt;在控制台中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆