Why does Xcode print quot;[LogMessageLogging] lt;privategt;quot; in console?(为什么Xcode在控制台中打印q;[LogMessageLogging]lt;Privategt;quot;?)
本文介绍了为什么Xcode在控制台中打印&q;[LogMessageLogging]<;Private>;";?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用地图视图时,为什么Xcode 8(IOS 10)在控制台打印[LogMessageLogging] <private>
?
[LogMessageLogging]<;Private>;
谁能给点建议?
推荐答案
隐私
统一日志记录系统将动态字符串和复杂动态对象视为私有,并且不会自动收集它们。为确保用户隐私,建议日志消息严格由静态字符串和数字组成。在需要捕获动态字符串的情况下,可以显式使用关键字public声明该字符串。例如,
%{public}s
。
- 来源:https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code?language=objc
- WWDC视频:https://developer.apple.com/videos/play/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!
示例(SWIFT):
目前,SWIFT(https://openradar.appspot.com/radar?id=6068967584038912)中的日志记录字符串似乎已中断,因此我们需要手动将C函数桥接到SWIFT:
更新01。雷达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
这篇关于为什么Xcode在控制台中打印&q;[LogMessageLogging]<;Private>;";?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:为什么Xcode在控制台中打印&q;[LogMessageLogging]<;Private>;";?


猜你喜欢
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01