Skip to content

Commit 79795bf

Browse files
authored
Decrease verbosity of info-level logging (#331)
- Don't log entire LSP notifications/requests for the `info` level, instead log of the form: - `Notification<method>` e.g. Notification<textDocument/publishDiagnostics> - `Request<method(id)>` e.g. Request<textDocument/hover(6)> - `Response<method(id)` e.g. Response<textDocument/hover(6)> - Only log sourcekitd requests/responses at the debug level
1 parent 15d47d8 commit 79795bf

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

Sources/SKCore/BuildSystemManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ extension BuildSystemManager: BuildSystemDelegate {
388388

389389
extension BuildSystemManager: MainFilesDelegate {
390390

391+
// FIXME: Consider debouncing/limiting this, seems to trigger often during a build.
391392
public func mainFilesChanged() {
392393
queue.async {
393394
let origWatched = self.watchedFiles

Sources/SKCore/LanguageServer.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,28 @@ open class LanguageServerEndpoint {
8181
}
8282

8383
open func _logRequest<R>(_ request: Request<R>) {
84-
logAsync { _ in
85-
"\(type(of: self)): \(request)"
84+
logAsync { currentLevel in
85+
guard currentLevel >= LogLevel.debug else {
86+
return "\(type(of: self)): Request<\(R.method)(\(request.id))>"
87+
}
88+
return "\(type(of: self)): \(request)"
8689
}
8790
}
8891
open func _logNotification<N>(_ notification: Notification<N>) {
89-
logAsync { _ in
90-
"\(type(of: self)): \(notification)"
92+
logAsync { currentLevel in
93+
guard currentLevel >= LogLevel.debug else {
94+
return "\(type(of: self)): Notification<\(N.method)>"
95+
}
96+
return "\(type(of: self)): \(notification)"
9197
}
9298
}
9399
open func _logResponse<Response>(_ result: LSPResult<Response>, id: RequestID, method: String) {
94-
logAsync { _ in
95-
"""
96-
\(type(of: self)): Response<\(method)>(
100+
logAsync { currentLevel in
101+
guard currentLevel >= LogLevel.debug else {
102+
return "\(type(of: self)): Response<\(method)(\(id))>"
103+
}
104+
return """
105+
\(type(of: self)): Response<\(method)(\(id))>(
97106
\(result)
98107
)
99108
"""
@@ -158,7 +167,6 @@ extension LanguageServerEndpoint: MessageHandler {
158167
queue.async {
159168

160169
let notification = Notification(params, clientID: clientID)
161-
162170
self._logNotification(notification)
163171

164172
guard let handler = self.notificationHandlers[ObjectIdentifier(N.self)] as? ((Notification<N>) -> Void) else {

Sources/SourceKitD/SourceKitD.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extension SourceKitD {
6969

7070
/// Send the given request and synchronously receive a reply dictionary (or error).
7171
public func sendSync(_ req: SKDRequestDictionary) throws -> SKDResponseDictionary {
72-
logAsync { _ in req.description }
72+
logRequest(req)
7373

7474
let resp = SKDResponse(api.send_request_sync(req.dict), sourcekitd: self)
7575

@@ -88,7 +88,7 @@ extension SourceKitD {
8888
_ queue: DispatchQueue,
8989
reply: @escaping (Result<SKDResponseDictionary, SKDError>) -> Void
9090
) -> sourcekitd_request_handle_t? {
91-
logAsync { _ in req.description }
91+
logRequest(req)
9292

9393
var handle: sourcekitd_request_handle_t? = nil
9494

@@ -115,6 +115,12 @@ extension SourceKitD {
115115
}
116116
}
117117

118+
private func logRequest(_ request: SKDRequestDictionary) {
119+
// FIXME: Ideally we could log the request key here at the info level but the dictionary is
120+
// readonly.
121+
logAsync(level: .debug) { _ in request.description }
122+
}
123+
118124
private func logResponse(_ response: SKDResponse) {
119125
if let value = response.value {
120126
logAsync(level: .debug) { _ in value.description }

Sources/SourceKitLSP/IndexStoreDB+MainFilesProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension IndexStoreDB: MainFilesProvider {
2424
} else {
2525
mainFiles = []
2626
}
27-
log("mainFilesContainingFile(\(uri.pseudoPath)) -> \(mainFiles)")
27+
log("mainFilesContainingFile(\(uri.pseudoPath)) -> \(mainFiles)", level: .debug)
2828
return mainFiles
2929
}
3030
}

0 commit comments

Comments
 (0)