お久しぶりです、岩手でiOSアプリを開発しているkzumuです。
最強のデバッグログを考えたのでよかったら御覧ください。
Gistにも上げてあります。
import Foundation
enum Level {
case debug
case error
}
func debugLog(_ elements: Any..., file: String = #file, function: String = #function, line: Int = #line, level: Level = .debug) {
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd HH:mm:ss"
switch level {
case .debug:
print("🌟 ", terminator: "")
case .error:
print("⚠️ ", terminator: "")
}
let file = URL(fileURLWithPath: file).lastPathComponent
print("\(df.string(from: Date())): \(file):\(line) \(function):", terminator: "")
elements.forEach {
print(" \($0)", terminator: "")
}
print()
}