Skip to content

Commit

Permalink
Merge branch 'swift2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjehpark committed Jan 25, 2017
2 parents f865cb2 + 6c12ed1 commit 72bcd3b
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Swift2/Log.swift
Original file line number Diff line number Diff line change
@@ -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/
}

0 comments on commit 72bcd3b

Please sign in to comment.