mirror of
https://github.com/jphong1111/awesome-ios-developer.git
synced 2025-01-03 13:31:09 +07:00
41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
//
|
|
// NetworkLogger.swift
|
|
// MapDemoApp
|
|
//
|
|
// Created by JungpyoHong on 4/25/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class NetworkLogger {
|
|
static func log(request: URLRequest) {
|
|
|
|
print("\n - - - - - - - - - - OUTGOING - - - - - - - - - - \n")
|
|
defer { print("\n - - - - - - - - - - END - - - - - - - - - - \n") }
|
|
|
|
let urlAsString = request.url?.absoluteString ?? ""
|
|
let urlComponents = NSURLComponents(string: urlAsString)
|
|
|
|
let method = request.httpMethod != nil ? "\(request.httpMethod ?? "")" : ""
|
|
let path = "\(urlComponents?.path ?? "")"
|
|
let query = "\(urlComponents?.query ?? "")"
|
|
let host = "\(urlComponents?.host ?? "")"
|
|
|
|
var logOutput = """
|
|
\(urlAsString) \n\n
|
|
\(method) \(path)?\(query) HTTP/1.1 \n
|
|
HOST: \(host)\n
|
|
"""
|
|
for (key,value) in request.allHTTPHeaderFields ?? [:] {
|
|
logOutput += "\(key): \(value) \n"
|
|
}
|
|
if let body = request.httpBody {
|
|
logOutput += "\n \(NSString(data: body, encoding: String.Encoding.utf8.rawValue) ?? "")"
|
|
}
|
|
|
|
print(logOutput)
|
|
}
|
|
|
|
static func log(response: URLResponse) {}
|
|
}
|