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
112 lines (101 loc) · 3.15 KB
/
Logger.swift
File metadata and controls
112 lines (101 loc) · 3.15 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
private let osLog: OSLog
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 static let gitHubCopilot = Logger(category: "GitHubCopilot")
public static let codeium = Logger(category: "Codeium")
public static let langchain = Logger(category: "LangChain")
public static let retrieval = Logger(category: "Retrieval")
public static let license = Logger(category: "License")
public static let `extension` = Logger(category: "Extension")
#if DEBUG
/// Use a temp logger to log something temporary. I won't be available in release builds.
public static let temp = Logger(category: "Temp")
#endif
public init(subsystem: String = "com.intii.CopilotForXcode", category: String) {
self.subsystem = subsystem
self.category = category
osLog = OSLog(subsystem: subsystem, category: category)
}
func log(
level: LogLevel,
message: String,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
let osLogType: OSLogType
switch level {
case .debug:
osLogType = .debug
case .info:
osLogType = .info
case .error:
osLogType = .error
}
os_log("%{public}@", log: osLog, type: osLogType, message as CVarArg)
}
public func debug(
_ message: String,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
log(level: .debug, message: """
\(message)
file: \(file)
line: \(line)
function: \(function)
""", file: file, line: line, function: function)
}
public func info(
_ message: String,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
log(level: .info, message: message, file: file, line: line, function: function)
}
public func error(
_ message: String,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
log(level: .error, message: message, file: file, line: line, function: function)
}
public func error(
_ error: Error,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
log(
level: .error,
message: error.localizedDescription,
file: file,
line: line,
function: function
)
}
public func signpost(
_ type: OSSignpostType,
name: StaticString,
file: StaticString = #file,
line: UInt = #line,
function: StaticString = #function
) {
os_signpost(type, log: osLog, name: name)
}
}