Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

By default don't print to the console and add a configuration option to set it to enabled. #244

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions netfox/Core/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ private func podPlistVersion() -> String? {
return path
}

internal func nfxPrint(_ value: String) {
guard NFX.sharedInstance().printLoggingEnabled else { return }
print(value)
}

// TODO: Carthage support
let nfxVersion = podPlistVersion() ?? "0"

Expand Down Expand Up @@ -70,6 +75,9 @@ open class NFX: NSObject {
case custom
}

/// Change this value to `true` to show internal print logging in the console.
public var printLoggingEnabled: Bool = false

@objc open func start() {
guard !started else {
showMessage(Constants.alreadyStartedMessage.rawValue)
Expand Down
4 changes: 2 additions & 2 deletions netfox/Core/NFXHTTPModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
do {
try dataString.write(to: fileURL, atomically: true, encoding: .utf8)
} catch let error {
print("[NFX]: Failed to save data to [\(fileURL)] - \(error.localizedDescription)")
nfxPrint("[NFX]: Failed to save data to [\(fileURL)] - \(error.localizedDescription)")
}
}

@objc public func readRawData(from fileURL: URL) -> Data? {
do {
return try Data(contentsOf: fileURL)
} catch let error {
print("[NFX]: Failed to load data from [\(fileURL)] - \(error.localizedDescription)")
nfxPrint("[NFX]: Failed to load data from [\(fileURL)] - \(error.localizedDescription)")
return nil
}
}
Expand Down
8 changes: 4 additions & 4 deletions netfox/Core/NFXHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ struct NFXPath {
do {
try FileManager.default.createDirectory(at: nfxDirURL, withIntermediateDirectories: true, attributes: nil)
} catch let error {
print("[NFX]: failed to create working dir - \(error.localizedDescription)")
nfxPrint("[NFX]: failed to create working dir - \(error.localizedDescription)")
}
}

Expand All @@ -354,7 +354,7 @@ struct NFXPath {
do {
try FileManager.default.removeItem(at: nfxDirURL)
} catch let error {
print("[NFX]: failed to delete working dir - \(error.localizedDescription)")
nfxPrint("[NFX]: failed to delete working dir - \(error.localizedDescription)")
}
}

Expand Down Expand Up @@ -394,7 +394,7 @@ extension String {
try fileHandle.seekToEnd()
try fileHandle.write(contentsOf: data)
} catch let error {
print("[NFX]: Failed to append [\(self.prefix(128))] to \(fileURL), trying to create new file - \(error.localizedDescription)")
nfxPrint("[NFX]: Failed to append [\(self.prefix(128))] to \(fileURL), trying to create new file - \(error.localizedDescription)")
write(to: fileURL)
}
} else {
Expand All @@ -408,7 +408,7 @@ extension String {
do {
try write(to: fileURL, atomically: true, encoding: .utf8)
} catch let error {
print("[NFX]: Failed to save [\(self.prefix(128))] to \(fileURL) - \(error.localizedDescription)")
nfxPrint("[NFX]: Failed to save [\(self.prefix(128))] to \(fileURL) - \(error.localizedDescription)")
}
}

Expand Down