LoginSignup
0
1

More than 3 years have passed since last update.

SwiftLog、XcodeのOutput出力であれば、バックエンド使わず、Extension追加で賄う

Posted at

SwiftLog

https://github.com/apple/swift-log

Swift Packageです。

Extension

import Logging

extension Logger {
    static var level = Logger.Level.info

    init(function: String = #function) {
        self.init(label: function)
        self.logLevel = Logger.level
    }

    func trace(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.trace(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func debug(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.debug(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func info(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.info(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func notice(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.notice(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func warning(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.warning(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func error(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.error(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }

    func critical(_ message: String = "" , function: String = #function, line: Int = #line) {
        self.critical(Logger.Message(stringLiteral: String("[\(function):\(line)] \(message)")))
    }
}

Example

import UIKit
import Logging

class ViewController: UIViewController {

    let logger = Logger()

    override func viewDidLoad() {
        super.viewDidLoad()
        logger.info()
        logger.info("start")
 :
 :
 :
0
1
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
0
1