对 Apple 新的 Swift 日志记录 API 的封装,特别是 Logger。
在给定的级别(例如 debug
(默认))提供基本的 public
/ private
日志记录功能。
有关更多信息,请参考此 WWDC20 视频:探索 Swift 中的日志记录
import AppLogger
// Create an instance of the "AppLogger with default options.
let logger = AppLogger()
// Log public information.
logger.log("iPhone screen size: \(screenSize)")
// Log private information.
logger.log("Username: \(username); Password: \(password)", isPrivate: true)
public struct Defaults {
public static let subsystem = Bundle.main.bundleIdentifier ?? "AppLogger"
public static let category = "default"
public static let isPrivate = false
}
Action / Include Info/Debug Messages
,以便查看来自您的应用程序的 debug messages
。
请记住,如果设备连接到调试器,私有信息仍然会在 Console app 中以明文形式显示。 显然这是设计使然。
使用 Xcode 的 内置 SPM 支持。
在您的 Package.swift
中,将 AppLogger
添加为依赖项
dependencies: [
.package(url: "https://github.com/backslash-f/applogger", from: "1.0.0")
],
将依赖项与您的目标关联
targets: [
.target(name: "App", dependencies: ["AppLogger"])
]
运行:swift build