Created
September 9, 2021 08:02
-
-
Save cedricbahirwe/33e9ecc99d209e847de0ce7654b5b097 to your computer and use it in GitHub Desktop.
A monolithic class for printing logs when dealing with Networking
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
class DebuggingResource: NSObject { | |
private static func printLine(_ line: String) { | |
print("--- \(line) ---") | |
} | |
public static func logJsonDataFormat(_ data: Data) { | |
printLine("Start Debugging Json Format") | |
if let json = try? JSONSerialization.jsonObject(with: data) { | |
print(json) | |
} else { | |
print("Can not log the json") | |
} | |
printLine("End Debugging Json Format") | |
} | |
public static func logJsonDataFormat(_ data: Data, code: Int) { | |
printLine("Status code: \(code)") | |
logJsonDataFormat(data) | |
} | |
public static func logError(_ message: Error, from origin: String) { | |
} | |
public static func logMessage(_ message: String, from origin: String? = nil) { | |
if let origin = origin { | |
printLine("Message from \(origin)") | |
printLine(message) | |
} else { | |
printLine(message) | |
} | |
} | |
public static func logContent(_ values: Any...) { | |
printLine("Start Logging Content") | |
values.forEach { print($0) } | |
printLine("End Logging Content") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment