forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.swift
More file actions
54 lines (44 loc) · 1.38 KB
/
Logger.swift
File metadata and controls
54 lines (44 loc) · 1.38 KB
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
50
51
52
53
54
import Foundation
import os.log
enum LogLevel: String {
case debug
case info
case error
}
public final class Logger {
private let subsystem: String
private let category: String
public static let service = Logger(category: "Service")
public static let ui = Logger(category: "UI")
public static let client = Logger(category: "Client")
public static let updateChecker = Logger(category: "UpdateChecker")
public init(subsystem: String = "com.intii.CopilotForXcode", category: String) {
self.subsystem = subsystem
self.category = category
}
func log(level: LogLevel, message: String) {
let osLogType: OSLogType
switch level {
case .debug:
osLogType = .debug
case .info:
osLogType = .info
case .error:
osLogType = .error
}
let osLog = OSLog(subsystem: subsystem, category: category)
os_log("%@", log: osLog, type: osLogType, message as CVarArg)
}
public func debug(_ message: String) {
log(level: .debug, message: message)
}
public func info(_ message: String) {
log(level: .info, message: message)
}
public func error(_ message: String) {
log(level: .error, message: message)
}
public func error(_ error: Error) {
log(level: .error, message: error.localizedDescription)
}
}