LoginSignup
5
3

More than 3 years have passed since last update.

開発効率を最大化するための最強のデバッグログ

Last updated at Posted at 2018-07-28

お久しぶりです、岩手で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()
}

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3