-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pretty printed logs for the data
- Loading branch information
Showing
6 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Data+PrettyPrinted.swift | ||
// | ||
// | ||
// Created by Manu on 28/05/2023. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Data { | ||
var prettyPrintedJSONString: NSString { | ||
guard let object = try? JSONSerialization.jsonObject( | ||
with: self, | ||
options: [] | ||
), let data = try? JSONSerialization.data( | ||
withJSONObject: object, | ||
options: [.prettyPrinted] | ||
), let prettyPrintedString = NSString( | ||
data: data, | ||
encoding: String.Encoding.utf8.rawValue | ||
) else { return "" } | ||
|
||
return prettyPrintedString | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Request+Properties.swift | ||
// | ||
// | ||
// Created by Manu on 28/05/2023. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Request { | ||
var logProperties: [String: Any] { | ||
var logProperties: [String: Any] = [:] | ||
logProperties["Request's Internal Id"] = internalId | ||
if let url = urlRequest.url { | ||
logProperties["URL"] = url.absoluteString | ||
} | ||
logProperties["HTTP Method"] = urlRequest.httpMethod | ||
if let headers = urlRequest.allHTTPHeaderFields, headers.count > 0 { | ||
logProperties["HTTP Headers"] = headers | ||
} | ||
if let body = urlRequest.httpBody { | ||
logProperties["HTTP Body"] = String(data: body, encoding: .utf8) | ||
} | ||
return logProperties | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters