-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
} |