-
-
Notifications
You must be signed in to change notification settings - Fork 624
/
Copy pathLog.swift
49 lines (38 loc) · 1.17 KB
/
Log.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Darwin
import Foundation
/// :nodoc:
public enum Log {
public enum Level: Int {
case errors
case warnings
case info
case verbose
}
public static var level: Level = .warnings
public static var logBenchmarks: Bool = false
public static func error(_ message: Any) {
log(level: .errors, "error: \(message)")
// to return error when running swift templates which is done in a different process
if ProcessInfo().processName != "Sourcery" {
fputs("\(message)", stderr)
}
}
public static func warning(_ message: Any) {
log(level: .warnings, "warning: \(message)")
}
public static func verbose(_ message: Any) {
log(level: .verbose, message)
}
public static func info(_ message: Any) {
log(level: .info, message)
}
public static func benchmark(_ message: Any) {
guard logBenchmarks else { return }
print(message)
}
private static func log(level logLevel: Level, _ message: Any) {
guard logLevel.rawValue <= Log.level.rawValue else { return }
print(message)
}
}
extension String: Error {}