From 6c12ed17d63596abb2c9290a232fb9ebe4228f0d Mon Sep 17 00:00:00 2001 From: yangjehpark Date: Wed, 25 Jan 2017 11:38:25 +0900 Subject: [PATCH] swift 2.3 version --- Swift2/Log.swift | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Swift2/Log.swift diff --git a/Swift2/Log.swift b/Swift2/Log.swift new file mode 100644 index 0000000..193922c --- /dev/null +++ b/Swift2/Log.swift @@ -0,0 +1,70 @@ +// +// Log.swift +// Swift 2.3 +// +// Created by yangjehpark on 2017. 1. 18.. +// Copyright Š 2017 yangjehpark. All rights reserved. +// + +import Foundation + +/// Basic log +func log(message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.enable()) { + print("\(Log.time())✅(\(Log.fileName(file)):\(line))📝\(message)") + } +} + +/// Log class +struct Log { + + private static func enable() -> Bool { + #if !RELEASE + return true + #else + return false + #endif + } + + /// debug + static func d(message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.enable()) { + print("\(Log.time())đŸ”Ŧ(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// info + static func i(message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.enable()) { + print("\(Log.time())ℹī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// warning + static func w(message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.enable()) { + print("\(Log.time())⚠ī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// error. + static func e(message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.enable()) { + print("\(Log.time())⛔ī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// Time stamp for Log + private static func time() -> String { + let dateFormatter: NSDateFormatter = NSDateFormatter() + dateFormatter.dateFormat = "HH:mm:ss:SSSS" + return "🕒"+dateFormatter.stringFromDate(NSDate()) + } + + /// Simplified file name + private static func fileName(file: String) -> String { + return (file as NSString).lastPathComponent.stringByReplacingOccurrencesOfString(".swift", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil) + } + + // More emoticons list is here 👉 http://www.grumdrig.com/emoji-list/ +} \ No newline at end of file