Skip to content

Commit

Permalink
Merge pull request #36 from allaboutapps/feature/logging-performance-…
Browse files Browse the repository at this point in the history
…improvement

Checking verbose before doing parsing, decoding, prettyfying
  • Loading branch information
mpoimer authored Jul 17, 2023
2 parents 18c9251 + 1dc88f2 commit 5797aef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Sources/Fetch/Network/APILogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public class APILogger: EventMonitor {
output.append("↗️\(isStubbed ? " [STUB]" : "") \(urlRequest.httpMethod ?? "") - \(urlRequest.url?.absoluteString ?? "")")

let spacing = " "
if let headers = urlRequest.allHTTPHeaderFields, verbose {
if verbose, let headers = urlRequest.allHTTPHeaderFields {
output.append("\(spacing)Headers:")
let formattedHeaders = headers
.map { "\(spacing) \($0.0): \($0.1)" }
.joined(separator: "\n")
output.append(formattedHeaders)
}

if let body = prettyJSON(data: urlRequest.httpBody), verbose {
if verbose, let body = prettyJSON(data: urlRequest.httpBody) {
output.append("\(spacing)Request Body:")
output.append(body)
}
Expand All @@ -86,8 +86,9 @@ public class APILogger: EventMonitor {

output.append("\(icon)\(isStubbed ? " [STUB]" : "") \(response.statusCode) \(urlRequest.httpMethod ?? "") - \(urlRequest.url?.absoluteString ?? "")")

if let data = (request as? DataRequest)?.data,
let body = prettyJSON(data: data) ?? String(data: data, encoding: .utf8), verbose {
if verbose,
let data = (request as? DataRequest)?.data,
let body = prettyJSON(data: data) ?? String(data: data, encoding: .utf8) {
output.append(body)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/FetchTests/Cache/CacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class CacheTests: XCTestCase {
}
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
resource.fetch { (result, isFinished) in
switch result {
case let .success(.cache(value, isExpired)):
Expand Down

0 comments on commit 5797aef

Please sign in to comment.