@@ -10,17 +10,17 @@ import Foundation
10
10
enum Log {
11
11
enum LogLevel {
12
12
case info,
13
- warning,
14
- error
13
+ warning,
14
+ error
15
15
16
16
fileprivate var prefix : String {
17
17
switch self {
18
18
case . info:
19
- return " INFO "
19
+ return " ℹ️ "
20
20
case . warning:
21
- return " WARN ⚠️"
21
+ return " ⚠️ "
22
22
case . error:
23
- return " ALERT ❌"
23
+ return " ❌ "
24
24
}
25
25
}
26
26
}
@@ -31,15 +31,24 @@ enum Log {
31
31
let line : Int
32
32
33
33
var description : String {
34
- return " \( ( file as NSString ) . lastPathComponent) : \( line) \( function) "
34
+ return " [ \( ( file as NSString ) . lastPathComponent) : \( line) \( function) ] "
35
35
}
36
36
}
37
37
38
+ static fileprivate var dateFormatter : DateFormatter {
39
+ let formatter = DateFormatter ( )
40
+ formatter. dateFormat = " yyyy-MM-dd hh:mm:ss "
41
+ formatter. locale = Locale . current
42
+ formatter. timeZone = TimeZone . current
43
+ return formatter
44
+ }
45
+
38
46
fileprivate static func handleLog( level: LogLevel , str: String , shouldLogContext: Bool , context: Context ) {
39
- var logComponents = [ " [ \( level . prefix ) ] " , " -> \( str ) " ]
47
+ var logComponents = [ Date ( ) . toString ( ) , " [ \( level . prefix ) ] " ]
40
48
if shouldLogContext {
41
49
logComponents. insert ( " \( context. description) " , at: 1 )
42
50
}
51
+ logComponents. append ( " -> \( str) " )
43
52
44
53
#if DEBUG
45
54
print ( logComponents. joined ( separator: " " ) )
@@ -51,3 +60,9 @@ enum Log {
51
60
Log . handleLog ( level: logLevel, str: str. description, shouldLogContext: shouldLogContext, context: context)
52
61
}
53
62
}
63
+
64
+ internal extension Date {
65
+ func toString( ) -> String {
66
+ return Log . dateFormatter. string ( from: self as Date )
67
+ }
68
+ }
0 commit comments