Skip to content

Commit b889772

Browse files
committed
Increase log level for request responses
The request responses are interesting to see to diagnose issues. Log them at the `log` instead of `debug` level instead.
1 parent 78c28f5 commit b889772

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

Sources/LanguageServerProtocol/Request.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,26 @@ extension Notification: CustomStringConvertible, CustomLogStringConvertible {
129129
return "Notification<\(N.method)>"
130130
}
131131
}
132+
133+
fileprivate struct AnyResponseType: CustomLogStringConvertible {
134+
let response: any ResponseType
135+
136+
var description: String {
137+
return """
138+
\(type(of: response))
139+
\(response.prettyPrintJSON)
140+
"""
141+
}
142+
143+
var redactedDescription: String {
144+
return """
145+
\(type(of: response))
146+
"""
147+
}
148+
}
149+
150+
extension ResponseType {
151+
public var forLogging: CustomLogStringConvertibleWrapper {
152+
return AnyResponseType(response: self).forLogging
153+
}
154+
}

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,14 +713,24 @@ extension SourceKitServer: MessageHandler {
713713
reply(result)
714714
let endDate = Date()
715715
Task {
716-
logger.debug(
717-
"""
718-
Sending response (took \(endDate.timeIntervalSince(startDate) * 1000, privacy: .public)ms)
719-
Response<\(R.method, privacy: .public)(\(id, privacy: .public))>(
720-
\(String(describing: result))
716+
switch result {
717+
case .success(let response):
718+
logger.log(
719+
"""
720+
Succeeded (took \(endDate.timeIntervalSince(startDate) * 1000, privacy: .public)ms)
721+
\(R.method, privacy: .public)
722+
\(response.forLogging)
723+
"""
721724
)
722-
"""
723-
)
725+
case .failure(let error):
726+
logger.log(
727+
"""
728+
Failed (took \(endDate.timeIntervalSince(startDate) * 1000, privacy: .public)ms)
729+
\(R.method, privacy: .public)(\(id, privacy: .public))
730+
\(error.forLogging, privacy: .private)
731+
"""
732+
)
733+
}
724734
}
725735
}
726736
)

0 commit comments

Comments
 (0)