"?-6ren"> "?-为什么 Xcode 8 (iOS 10) 打印 [LogMessageLogging] 在控制台中,当我调用 map View 时? [LogMessageLogging] 谁能给点建议? 最佳答案-6ren">
gpt4 book ai didi

ios - 为什么 Xcode 在控制台中打印 "[LogMessageLogging] "?

转载 作者:可可西里 更新时间:2023-11-01 03:39:40 27 4
gpt4 key购买 nike

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

[LogMessageLogging] <private>

谁能给点建议?

"" printed to console

最佳答案

Privacy

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.


示例(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!

示例( swift ):

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

更新 01。 Radar 28599032 已修复,不适用于 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

关于ios - 为什么 Xcode 在控制台中打印 "[LogMessageLogging] <private>"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38344674/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com