Adjust logging level for frequent / low-level events (#130)

This commit is contained in:
Mattt 2025-06-05 05:36:37 -07:00 • committed by GitHub
commit 7a76001187
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 19 deletions

View file

@ -131,7 +131,7 @@ public actor HTTPClientTransport: Transport {
if let continuation = self.initialSessionIDContinuation {
continuation.resume()
self.initialSessionIDContinuation = nil // Consume the continuation
logger.debug("Initial session ID signal triggered for SSE task.")
logger.trace("Initial session ID signal triggered for SSE task.")
}
}
@ -251,7 +251,7 @@ public actor HTTPClientTransport: Transport {
logger.warning("SSE responses aren't fully supported on Linux")
messageContinuation.yield(data)
} else if contentType.contains("application/json") {
logger.debug("Received JSON response", metadata: ["size": "\(data.count)"])
logger.trace("Received JSON response", metadata: ["size": "\(data.count)"])
messageContinuation.yield(data)
} else {
logger.warning("Unexpected content type: \(contentType)")
@ -285,7 +285,7 @@ public actor HTTPClientTransport: Transport {
if contentType.contains("text/event-stream") {
// For SSE, processing happens via the stream
logger.debug("Received SSE response, processing in streaming task")
logger.trace("Received SSE response, processing in streaming task")
try await self.processSSE(stream)
} else if contentType.contains("application/json") {
// For JSON responses, collect and deliver the data
@ -293,7 +293,7 @@ public actor HTTPClientTransport: Transport {
for try await byte in stream {
buffer.append(byte)
}
logger.debug("Received JSON response", metadata: ["size": "\(buffer.count)"])
logger.trace("Received JSON response", metadata: ["size": "\(buffer.count)"])
messageContinuation.yield(buffer)
} else {
logger.warning("Unexpected content type: \(contentType)")
@ -390,7 +390,7 @@ public actor HTTPClientTransport: Transport {
// Wait for the initial session ID signal, but only if sessionID isn't already set
if self.sessionID == nil, let signalTask = self.initialSessionIDSignalTask {
logger.debug("SSE streaming task waiting for initial sessionID signal...")
logger.trace("SSE streaming task waiting for initial sessionID signal...")
// Race the signalTask against a timeout
let timeoutTask = Task {
@ -429,14 +429,14 @@ public actor HTTPClientTransport: Transport {
timeoutTask.cancel()
if signalReceived {
logger.debug("SSE streaming task proceeding after initial sessionID signal.")
logger.trace("SSE streaming task proceeding after initial sessionID signal.")
} else {
logger.warning(
"Timeout waiting for initial sessionID signal. SSE stream will proceed (sessionID might be nil)."
)
}
} else if self.sessionID != nil {
logger.debug(
logger.trace(
"Initial sessionID already available. Proceeding with SSE streaming task immediately."
)
} else {
@ -525,7 +525,7 @@ public actor HTTPClientTransport: Transport {
// Check if task has been cancelled
if Task.isCancelled { break }
logger.debug(
logger.trace(
"SSE event received",
metadata: [
"type": "\(event.event ?? "message")",

View file

@ -408,7 +408,7 @@ import Logging
})
}
logger.debug("Heartbeat sent")
logger.trace("Heartbeat sent")
}
/// Handles connection failure
@ -638,11 +638,11 @@ import Logging
// Check if this is a heartbeat message
if Heartbeat.isHeartbeat(newData) {
logger.debug("Received heartbeat from peer")
logger.trace("Received heartbeat from peer")
// Extract timestamp if available
if let heartbeat = Heartbeat.from(data: newData) {
logger.debug("Heartbeat timestamp: \(heartbeat.timestamp)")
logger.trace("Heartbeat timestamp: \(heartbeat.timestamp)")
}
// Reset the counter since we got valid data
@ -783,7 +783,7 @@ import Logging
} else if let content = content {
continuation.resume(returning: content)
} else if isComplete {
self.logger.debug("Connection completed by peer")
self.logger.trace("Connection completed by peer")
continuation.resume(throwing: MCPError.connectionClosed)
} else {
// EOF: Resume with empty data instead of throwing an error

View file

@ -155,7 +155,7 @@ import struct Foundation.Data
pendingData = pendingData[(newlineIndex + 1)...]
if !messageData.isEmpty {
logger.debug(
logger.trace(
"Message received", metadata: ["size": "\(messageData.count)"])
messageContinuation.yield(Data(messageData))
}

View file

@ -659,7 +659,7 @@ public actor Client {
// MARK: -
private func handleResponse(_ response: Response<AnyMethod>) async {
await logger?.debug(
await logger?.trace(
"Processing response",
metadata: ["id": "\(response.id)"])
@ -684,7 +684,7 @@ public actor Client {
}
private func handleMessage(_ message: Message<AnyNotification>) async {
await logger?.debug(
await logger?.trace(
"Processing notification",
metadata: ["method": "\(message.method)"])
@ -728,7 +728,7 @@ public actor Client {
// Add handler for batch responses
private func handleBatchResponse(_ responses: [AnyResponse]) async {
await logger?.debug("Processing batch response", metadata: ["count": "\(responses.count)"])
await logger?.trace("Processing batch response", metadata: ["count": "\(responses.count)"])
for response in responses {
// Attempt to remove the pending request.
// If successful, pendingRequest contains the request.

View file

@ -380,7 +380,7 @@ public actor Server {
/// Process a batch of requests and/or notifications
private func handleBatch(_ batch: Batch) async throws {
await logger?.debug("Processing batch request", metadata: ["size": "\(batch.items.count)"])
await logger?.trace("Processing batch request", metadata: ["size": "\(batch.items.count)"])
if batch.items.isEmpty {
// Empty batch is invalid according to JSON-RPC spec
@ -450,7 +450,7 @@ public actor Server {
)
}
await logger?.debug(
await logger?.trace(
"Processing request",
metadata: [
"method": "\(request.method)",
@ -505,7 +505,7 @@ public actor Server {
}
private func handleMessage(_ message: Message<AnyNotification>) async throws {
await logger?.debug(
await logger?.trace(
"Processing notification",
metadata: ["method": "\(message.method)"])