-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from hotwired/disable-logging-by-default
Expose a new `TurboLog.debugLoggingEnabled` API that apps can enable to see debug logs
- Loading branch information
Showing
3 changed files
with
28 additions
and
9 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
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import Foundation | ||
|
||
public struct TurboLog { | ||
public static var debugLoggingEnabled = false | ||
} | ||
|
||
/// Simple function to help in debugging, a noop in Release builds | ||
func debugLog(_ text: String, _ arguments: [String: Any] = [:]) { | ||
#if DEBUG | ||
func debugLog(_ message: String, _ arguments: [String: Any] = [:]) { | ||
let timestamp = Date() | ||
|
||
print("\(timestamp) \(text) \(arguments)") | ||
|
||
#endif | ||
log("\(timestamp) \(message) \(arguments)") | ||
} | ||
|
||
func debugPrint(_ message: String) { | ||
#if DEBUG | ||
print(message) | ||
#endif | ||
log(message) | ||
} | ||
|
||
private func log(_ message: String) { | ||
if TurboLog.debugLoggingEnabled { | ||
print(message) | ||
} | ||
} |