Skip to content

Commit cb21f9a

Browse files
committed
Output a --- marker to mark the end of a log message in NonDarwinLogger
Figuring out where one log message ends and the next one starts is a little tricky. A `---` marker helped me a lot to find the boundary between two log messages.
1 parent 645b511 commit cb21f9a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/LSPLogging/NonDarwinLogging.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public struct NonDarwinLogger {
291291
"""
292292
[\(subsystem):\(category)] \(level) \(dateFormatter.string(from: date))
293293
\(message().value.string(for: self.privacyLevel))
294+
---
294295
"""
295296
)
296297
}

Tests/LSPLoggingTests/LoggingTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ fileprivate func assertLogging(
5757
)
5858
continue
5959
}
60-
let messageContent = String(message[message.index(after: firstNewline)...])
60+
guard message.hasSuffix("\n---") else {
61+
XCTFail("Message is expected to end with `---`", file: file, line: line)
62+
return
63+
}
64+
let messageContent = String(message[message.index(after: firstNewline)...].dropLast(4))
6165
XCTAssertEqual(messageContent, expected, "Message does not match expected", file: file, line: line)
6266
}
6367

@@ -82,7 +86,7 @@ final class LoggingTests: XCTestCase {
8286
message.starts(with: "[org.swift.sourcekit-lsp:test] error"),
8387
"Message did not have expected header. Received \n\(message)"
8488
)
85-
XCTAssert(message.hasSuffix("\nmy message"), "Message did not have expected body. Received \n\(message)")
89+
XCTAssert(message.hasSuffix("\nmy message\n---"), "Message did not have expected body. Received \n\(message)")
8690
}
8791

8892
func testLoggingBasic() {

0 commit comments

Comments
 (0)