Skip to content

Commit

Permalink
feat: add memory logger class
Browse files Browse the repository at this point in the history
Resolves: none.
  • Loading branch information
loay-ashraf committed May 25, 2024
1 parent ba9d7fd commit 6c8175c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RxNetworkKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
C68FB9C42C022A0800A52FC5 /* FileManager+SizeOfFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68FB9C32C022A0800A52FC5 /* FileManager+SizeOfFile.swift */; };
C68FB9C62C022A7A00A52FC5 /* String+SplitNameAndExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68FB9C52C022A7A00A52FC5 /* String+SplitNameAndExtension.swift */; };
C68FB9C82C024FEC00A52FC5 /* HTTPUploadLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68FB9C72C024FEC00A52FC5 /* HTTPUploadLogger.swift */; };
C68FB9CA2C02643000A52FC5 /* MemoryLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C68FB9C92C02643000A52FC5 /* MemoryLogger.swift */; };
C69A78562ACF001400ECF092 /* Docs.docc in Sources */ = {isa = PBXBuildFile; fileRef = C69A78552ACEFF3200ECF092 /* Docs.docc */; };
C69BDD082BFD0817007B4CEB /* HTTPUploadRequestFormFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69BDD072BFD0817007B4CEB /* HTTPUploadRequestFormFile.swift */; };
C6A9BEFA2A93F16200459E32 /* URLSessionConfiguration+setAdditionalHTTPHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A9BEF92A93F16200459E32 /* URLSessionConfiguration+setAdditionalHTTPHeader.swift */; };
Expand Down Expand Up @@ -148,6 +149,7 @@
C68FB9C32C022A0800A52FC5 /* FileManager+SizeOfFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+SizeOfFile.swift"; sourceTree = "<group>"; };
C68FB9C52C022A7A00A52FC5 /* String+SplitNameAndExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+SplitNameAndExtension.swift"; sourceTree = "<group>"; };
C68FB9C72C024FEC00A52FC5 /* HTTPUploadLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPUploadLogger.swift; sourceTree = "<group>"; };
C68FB9C92C02643000A52FC5 /* MemoryLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryLogger.swift; sourceTree = "<group>"; };
C69A78552ACEFF3200ECF092 /* Docs.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Docs.docc; sourceTree = "<group>"; };
C69BDD072BFD0817007B4CEB /* HTTPUploadRequestFormFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPUploadRequestFormFile.swift; sourceTree = "<group>"; };
C6A9BEF92A93F16200459E32 /* URLSessionConfiguration+setAdditionalHTTPHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLSessionConfiguration+setAdditionalHTTPHeader.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -265,6 +267,7 @@
children = (
C61A7E232B6276F800407C38 /* HTTPLogger.swift */,
C68FB9C72C024FEC00A52FC5 /* HTTPUploadLogger.swift */,
C68FB9C92C02643000A52FC5 /* MemoryLogger.swift */,
);
path = Logger;
sourceTree = "<group>";
Expand Down Expand Up @@ -676,6 +679,7 @@
C6EAFAEC2BF77B00008D3C2B /* HTTPRequestRetryPolicy.swift in Sources */,
0B77E0AE29D965D30077FBC0 /* Single+VerifyResponse.swift in Sources */,
C6EAFAED2BF77B00008D3C2B /* HTTPMethod.swift in Sources */,
C68FB9CA2C02643000A52FC5 /* MemoryLogger.swift in Sources */,
C6C643092BE6C9340071C2CC /* SecCertificate+Bundle.swift in Sources */,
0B77E0B429D965D30077FBC0 /* HTTPDownloadRequestRouter.swift in Sources */,
C68FB9C42C022A0800A52FC5 /* FileManager+SizeOfFile.swift in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions Source/Common/Request/Logger/MemoryLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// MemoryLogger.swift
// RxNetworkKit
//
// Created by Loay Ashraf on 25/05/2024.
//

import Foundation

final class MemoryLogger {

static let shared: MemoryLogger = .init()

private init() { }

func logLargeUploadFile(file: HTTPUploadRequestFile) {
let logMessage = makeLogMessage(for: file)
print(logMessage)
}

private func makeLogMessage(for file: HTTPUploadRequestFile) -> String {
var logMessage = ""

logMessage += "\n* * * * * * * * * * MEMORY WARNING * * * * * * * * * *\n"
logMessage += "\nHolding a large file for upload in the device memory (> 10 MB),\nPerformance may be reduced if the available memory is low.\n"
logMessage += "\nFile Details:\n"
logMessage += "- Name: \(file.name)\n"
logMessage += "- Type: \(file.mimeType.rawValue)\n"
logMessage += "- Size: \(file.size.formattedSize)\n"
logMessage += "\n* * * * * * * * * * * * * END * * * * * * * * * * * * *\n"

return logMessage
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public struct HTTPUploadRequestFile {
self.size = Int64(data.count)
#if DEBUG
if size > 10_485_760 {
print("* * * * * * * * * * MEMORY WARNING * * * * * * * * * *\n")
print("Holding a large file for upload in the device memory (> 10 MB)\nPerformance may be reduced if the available memory is low.")
print("\n* * * * * * * * * * * * * END * * * * * * * * * * * * *\n")
MemoryLogger.shared.logLargeUploadFile(file: self)
}
#endif
}
Expand Down

0 comments on commit 6c8175c

Please sign in to comment.