Skip to content

Commit

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

0 comments on commit de9df9f

Please sign in to comment.