From 60d582b4692e99978e81b520acc866206204931a Mon Sep 17 00:00:00 2001 From: yangjehpark Date: Wed, 25 Jan 2017 11:39:00 +0900 Subject: [PATCH] swift 3 version --- Swift3/Log.swift | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Swift3/Log.swift diff --git a/Swift3/Log.swift b/Swift3/Log.swift new file mode 100644 index 0000000..d7468c9 --- /dev/null +++ b/Swift3/Log.swift @@ -0,0 +1,71 @@ +// +// Log.swift +// Swift 3.1 +// +// 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.logEnabled()) { + print("\(Log.time())✅(\(Log.fileName(file)):\(line))📝\(message)") + } +} + +/// Log class +struct Log { + + /// show or ignore + fileprivate static func logEnabled() -> Bool { + #if !RELEASE + return true + #else + return false + #endif + } + + /// debug + public static func d(_ message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.logEnabled()) { + print("\(Log.time())đŸ”Ŧ(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// info + public static func i(_ message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.logEnabled()) { + print("\(Log.time())ℹī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// warning + public static func w(_ message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.logEnabled()) { + print("\(Log.time())⚠ī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// error + public static func e(_ message: String, file: String = #file, line: Int = #line, function: String = #function) { + if (Log.logEnabled()) { + print("\(Log.time())⛔ī¸(\(Log.fileName(file)):\(line))📝\(message)") + } + } + + /// Time stamp for Log + fileprivate static func time() -> String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "HH:mm:ss:SSSS" + return "🕒"+dateFormatter.string(from: Date()) + } + + /// Simplified file name + fileprivate static func fileName(_ file: String) -> String { + return (file as NSString).lastPathComponent.replacingOccurrences(of: ".swift", with: "") + } + + // More emoticons list is here 👉 http://www.grumdrig.com/emoji-list/ +}