- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
"?-6ren"> "?-为什么 Xcode 8 (iOS 10) 打印 [LogMessageLogging] 在控制台中,当我调用 map View 时? [LogMessageLogging] 谁能给点建议? 最佳答案-6ren">
为什么 Xcode 8 (iOS 10) 打印 [LogMessageLogging] <private>
在控制台中,当我调用 map View 时?
[LogMessageLogging] <private>
谁能给点建议?
最佳答案
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/
为什么 Xcode 8 (iOS 10) 打印 [LogMessageLogging] 在控制台中,当我调用 map View 时? [LogMessageLogging] 谁能给点建议? 最佳答案
我已在我的应用程序中添加了 MapKit。我已通过 IBOUTLET 将 MKmapview 连接到我的 View Controller ,它在模拟器中运行良好,但在我的设备中崩溃了 [LogMess
我是一名优秀的程序员,十分优秀!