File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -299,11 +299,20 @@ public struct NonDarwinLogger: Sendable {
299
299
guard level >= self . logLevel else { return }
300
300
let date = Date ( )
301
301
loggingQueue. async {
302
+ // Truncate log message after 10.000 characters to avoid flooding the log with huge log messages (eg. from a
303
+ // sourcekitd response). 10.000 characters was chosen because it seems to fit the result of most sourcekitd
304
+ // responses that are not generated interface or global completion results (which are a lot bigger).
305
+ var message = message ( ) . value. string ( for: self . privacyLevel)
306
+ if message. utf8. count > 10_000 {
307
+ // Check for UTF-8 byte length first because that's faster since it doesn't need to count UTF-8 characters.
308
+ // Truncate using `.prefix` to avoid cutting of in the middle of a UTF-8 multi-byte character.
309
+ message = message. prefix ( 10_000 ) + " ... "
310
+ }
302
311
// Start each log message with `[org.swift.sourcekit-lsp` so that it’s easy to split the log to the different messages
303
312
logHandler (
304
313
"""
305
314
[ \( subsystem) : \( category) ] \( level) \( dateFormatter. string ( from: date) )
306
- \( message ( ) . value . string ( for : self . privacyLevel ) )
315
+ \( message)
307
316
---
308
317
"""
309
318
)
You can’t perform that action at this time.
0 commit comments