wwdc2020 log

  1. 引入 log 库
  2. 自定义log 类型,便于搜索,一般般包名和模块
// Add logging to your app in three simple steps
 
import os

let logger = Logger(subsystem: "com.example.Fruta", category: "giftcards")

func beginTask(url: URL, handler: (Data) -> Void) {
    launchTask(with: url) {
       handler($0)
    }

    logger.log("Started a task")
}

public

logger.log("Ordered smoothie \(smoothieName, privacy: .public)")

格式化

logger.log("\(data, format: .hex, align: .right(columns: width))")
import SwiftUI
import os

let statisticsLogger = Logger(subsystem: "com.example.Fruta", category: "statistics")

// Log statistics about communication with a server.
func logStatistics(taskID: UUID, giftCardID: String, serverID: Int, seconds: Double) {
    statisticsLogger.log("\(taskID) \(giftCardID, align: .left(columns: GiftCard.maxIDLength)) \(serverID) \(seconds, format: .fixed(precision: 2))")
}

你可能感兴趣的:(wwdc2020 log)