Skip to content

Commit de9df9f

Browse files
author
yangjehpark
committed
Merge branch 'swift3'
2 parents 72bcd3b + 60d582b commit de9df9f

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Swift3/Log.swift

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// Log.swift
3+
// Swift 3.1
4+
//
5+
// Created by yangjehpark on 2017. 1. 18..
6+
// Copyright © 2017 yangjehpark. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Basic log
12+
func log(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
13+
if (Log.logEnabled()) {
14+
print("\(Log.time())✅(\(Log.fileName(file)):\(line))📝\(message)")
15+
}
16+
}
17+
18+
/// Log class
19+
struct Log {
20+
21+
/// show or ignore
22+
fileprivate static func logEnabled() -> Bool {
23+
#if !RELEASE
24+
return true
25+
#else
26+
return false
27+
#endif
28+
}
29+
30+
/// debug
31+
public static func d(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
32+
if (Log.logEnabled()) {
33+
print("\(Log.time())🔬(\(Log.fileName(file)):\(line))📝\(message)")
34+
}
35+
}
36+
37+
/// info
38+
public static func i(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
39+
if (Log.logEnabled()) {
40+
print("\(Log.time())ℹ️(\(Log.fileName(file)):\(line))📝\(message)")
41+
}
42+
}
43+
44+
/// warning
45+
public static func w(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
46+
if (Log.logEnabled()) {
47+
print("\(Log.time())⚠️(\(Log.fileName(file)):\(line))📝\(message)")
48+
}
49+
}
50+
51+
/// error
52+
public static func e(_ message: String, file: String = #file, line: Int = #line, function: String = #function) {
53+
if (Log.logEnabled()) {
54+
print("\(Log.time())⛔️(\(Log.fileName(file)):\(line))📝\(message)")
55+
}
56+
}
57+
58+
/// Time stamp for Log
59+
fileprivate static func time() -> String {
60+
let dateFormatter = DateFormatter()
61+
dateFormatter.dateFormat = "HH:mm:ss:SSSS"
62+
return "🕒"+dateFormatter.string(from: Date())
63+
}
64+
65+
/// Simplified file name
66+
fileprivate static func fileName(_ file: String) -> String {
67+
return (file as NSString).lastPathComponent.replacingOccurrences(of: ".swift", with: "")
68+
}
69+
70+
// More emoticons list is here 👉 http://www.grumdrig.com/emoji-list/
71+
}

0 commit comments

Comments
 (0)