Skip to content

Commit

Permalink
feature: network event logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Jihyun247 committed Jul 24, 2024
1 parent 8c281f3 commit 2bddaf2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Projects/Core/APIClient/Sources/Plugin/EventLoggerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,32 @@
//

import Foundation
import Shared

class EventLoggerDelegate: NSObject, URLSessionDelegate, URLSessionTaskDelegate, URLSessionDataDelegate {
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let error = error {
print("🛰 NETWORK Request Error: \(error.localizedDescription)")
} else {
print("🛰 NETWORK Request Completed Successfully")
}

if let request = task.originalRequest {
print("🛰 NETWORK Request LOG")
print(request.description)
print("URL: " + (request.url?.absoluteString ?? ""))
print("Method: " + (request.httpMethod ?? ""))
if let body = request.httpBody {
print("Body: " + (body.toPrettyPrintedString ?? ""))
}
}

if let response = task.response as? HTTPURLResponse {
print("🛰 NETWORK Response LOG")
print("StatusCode: \(response.statusCode)")
if let data = try? Data(contentsOf: response.url!) {
print("Data: \(data.toPrettyPrintedString ?? "")")
}
}
}
}

0 comments on commit 2bddaf2

Please sign in to comment.