From e76c6e14e4a0039d7a47c122cce079b799ba90e3 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 21 Dec 2021 17:06:03 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Added=20logger=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 8 +++ phpmon-cli/main.swift | 20 ++++--- phpmon-common/Core/Actions.swift | 12 ++--- phpmon-common/Core/Logger.swift | 52 +++++++++++++++++++ phpmon-common/PHP/PhpExtension.swift | 2 +- phpmon-common/PHP/PhpSwitcher.swift | 4 +- phpmon-tests/Utility.swift | 2 +- phpmon/Domain/Core/App+GlobalHotkey.swift | 4 +- .../Core/AppDelegate+Notifications.swift | 6 +-- phpmon/Domain/Core/AppDelegate.swift | 11 ++-- phpmon/Domain/Core/Startup.swift | 2 +- phpmon/Domain/Helpers/LocalNotification.swift | 2 +- .../Domain/Helpers/PMWindowController.swift | 2 +- .../Homebrew/HomebrewDiagnostics.swift | 16 +++--- phpmon/Domain/Integrations/Valet/Valet.swift | 8 +-- phpmon/Domain/Menu/MainMenu.swift | 20 +++---- phpmon/Domain/Preferences/Preferences.swift | 2 +- phpmon/Domain/Preferences/PrefsVC.swift | 2 +- phpmon/Domain/Preferences/PrefsWC.swift | 2 +- phpmon/Domain/Progress/ProgressWindow.swift | 4 +- phpmon/Domain/SiteList/SiteListVC.swift | 2 +- phpmon/Domain/Watcher/App+ConfigWatch.swift | 8 +-- phpmon/Domain/Watcher/PhpConfigWatcher.swift | 8 +-- 23 files changed, 135 insertions(+), 64 deletions(-) create mode 100644 phpmon-common/Core/Logger.swift diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 39cbd70..3a76475 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -35,6 +35,9 @@ C40C7F2827721FF600DDDCDC /* ActivePhpInstallation+Checks.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */; }; C40C7F2927721FF600DDDCDC /* ActivePhpInstallation+Checks.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */; }; C40C7F2B2772201C00DDDCDC /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3B62770F294005EF286 /* Actions.swift */; }; + C40C7F3027722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; }; + C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; }; + C40C7F3227722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; }; C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */; }; C415D3B72770F294005EF286 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3B62770F294005EF286 /* Actions.swift */; }; C415D3B82770F294005EF286 /* Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415D3B62770F294005EF286 /* Actions.swift */; }; @@ -189,6 +192,7 @@ C405A4CF24B9B9140062FAFA /* InternetAccessPolicy.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = InternetAccessPolicy.plist; sourceTree = ""; }; C40C7F1D2772136000DDDCDC /* PhpSwitcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpSwitcher.swift; sourceTree = ""; }; C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActivePhpInstallation+Checks.swift"; sourceTree = ""; }; + C40C7F2F27722E8D00DDDCDC /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomebrewPackage.swift; sourceTree = ""; }; C415D3B62770F294005EF286 /* Actions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Actions.swift; sourceTree = ""; }; C415D3D62770F341005EF286 /* phpmon-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "phpmon-cli"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -354,6 +358,7 @@ C4B5853D2770FE3900DA4FBE /* Command.swift */, C4B5853B2770FE3900DA4FBE /* Paths.swift */, C4B5853C2770FE3900DA4FBE /* Shell.swift */, + C40C7F2F27722E8D00DDDCDC /* Logger.swift */, ); path = Core; sourceTree = ""; @@ -745,6 +750,7 @@ C40C7F2327721F8200DDDCDC /* ActivePhpInstallation.swift in Sources */, C4B585462770FE3900DA4FBE /* Command.swift in Sources */, C40C7F2527721F9800DDDCDC /* HomebrewPackage.swift in Sources */, + C40C7F3227722E8D00DDDCDC /* Logger.swift in Sources */, C40C7F2B2772201C00DDDCDC /* Actions.swift in Sources */, C415D3E12770F34D005EF286 /* AllowedArguments.swift in Sources */, C40C7F202772136000DDDCDC /* PhpSwitcher.swift in Sources */, @@ -786,6 +792,7 @@ C48D0C9325CC804200CC7490 /* XibLoadable.swift in Sources */, 54FCFD2A276C8AA4004CE748 /* CheckboxPreferenceView.swift in Sources */, C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */, + C40C7F3027722E8D00DDDCDC /* Logger.swift in Sources */, C412E5FC25700D5300A1FB67 /* HomebrewPackage.swift in Sources */, 54AB03262763858F00A29D5F /* Timer.swift in Sources */, C4C8E81B276F54E5003AC782 /* PhpConfigWatcher.swift in Sources */, @@ -846,6 +853,7 @@ C4F780CD25D80B75000DBC97 /* Alert.swift in Sources */, C481F79726164A78004FBCFF /* PrefsVC.swift in Sources */, C41E871B2763D42300161EE0 /* SiteListVC+ContextMenu.swift in Sources */, + C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */, C464ADB3275A87CA003FCD53 /* SiteListCell.swift in Sources */, C415D3E92770F692005EF286 /* AppDelegate+InterApp.swift in Sources */, C4AF9F78275447F100D44ED0 /* ValetConfigParserTest.swift in Sources */, diff --git a/phpmon-cli/main.swift b/phpmon-cli/main.swift index 72fab89..decf4bb 100644 --- a/phpmon-cli/main.swift +++ b/phpmon-cli/main.swift @@ -15,17 +15,25 @@ import Foundation // Information about the PHP versions // etc.: needs to be stored in a separate object we can instantiate here and in PHP Monitor. -print(CommandLine.arguments) +var logger = Log.shared +logger.verbosity = .warning -if CommandLine.arguments.count != 3 { - print("You must enter two arguments.") +if CommandLine.arguments.count < 3 { + Log.err("You must enter at least two additional arguments.") exit(1) } +if CommandLine.arguments.contains("-v") || CommandLine.arguments.contains("--verbose") { + logger.verbosity = .info +} +if CommandLine.arguments.contains("-p") || CommandLine.arguments.contains("--performance") { + logger.verbosity = .performance +} + let argument = CommandLine.arguments[1] if !AllowedArguments.has(argument) { - print("The supported arguments are: \(AllowedArguments.rawValues)") + Log.err("The supported arguments are: \(AllowedArguments.rawValues)") exit(1) } @@ -37,9 +45,9 @@ PhpSwitcher.detectPhpVersions() switch action { case .use: let version = CommandLine.arguments[2] - print("Switching to PHP \(version)...") + Log.info("Switching to PHP \(version)...") break case .none: - print("Action not recognized!") + Log.err("Action not recognized!") exit(1) } diff --git a/phpmon-common/Core/Actions.swift b/phpmon-common/Core/Actions.swift index 0921845..7b3fdb1 100644 --- a/phpmon-common/Core/Actions.swift +++ b/phpmon-common/Core/Actions.swift @@ -42,8 +42,8 @@ class Actions { availableVersions: [String], completed: @escaping () -> Void ) { - print("Switching to \(version) using Valet") - print(valet("use php@\(version)")) + Log.info("Switching to \(version) using Valet") + Log.info(valet("use php@\(version)")) completed() } @@ -61,7 +61,7 @@ class Actions { availableVersions: [String], completed: @escaping () -> Void ) { - print("Switching to \(version), unlinking all versions...") + Log.info("Switching to \(version), unlinking all versions...") let group = DispatchGroup() @@ -80,14 +80,14 @@ class Actions { } group.notify(queue: .global(qos: .userInitiated)) { - print("All versions have been unlinked!") - print("Linking the new version!") + Log.info("All versions have been unlinked!") + Log.info("Linking the new version!") let formula = (version == PhpSwitcher.brewPhpVersion) ? "php" : "php@\(version)" brew("link \(formula) --overwrite --force") brew("services start \(formula)", sudo: true) - print("The new version has been linked!") + Log.info("The new version has been linked!") completed() } } diff --git a/phpmon-common/Core/Logger.swift b/phpmon-common/Core/Logger.swift new file mode 100644 index 0000000..a618ede --- /dev/null +++ b/phpmon-common/Core/Logger.swift @@ -0,0 +1,52 @@ +// +// Logger.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 21/12/2021. +// Copyright © 2021 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class Log { + + enum Verbosity: Int { + case error = 1, + info = 2, + warning = 3, + performance = 4 + + public func isApplicable() -> Bool { + return Log.shared.verbosity.rawValue >= self.rawValue + } + } + + static var shared = Log() + + var verbosity: Verbosity = .info + + static func info(_ item: Any) { + if Verbosity.info.isApplicable() { + print(item) + } + } + + static func err(_ item: Any) { + if Verbosity.error.isApplicable() { + print(item) + } + } + + static func warn(_ item: Any) { + if Verbosity.warning.isApplicable() { + print(item) + } + } + + static func perf(_ item: Any) { + if Verbosity.performance.isApplicable() { + print(item) + } + } + +} diff --git a/phpmon-common/PHP/PhpExtension.swift b/phpmon-common/PHP/PhpExtension.swift index 5268649..0996691 100644 --- a/phpmon-common/PHP/PhpExtension.swift +++ b/phpmon-common/PHP/PhpExtension.swift @@ -92,7 +92,7 @@ class PhpExtension { let file = try? String(contentsOf: path, encoding: .utf8) if (file == nil) { - print("There was an issue reading the file. Assuming no extensions were found.") + Log.err("There was an issue reading the file. Assuming no extensions were found.") return [] } diff --git a/phpmon-common/PHP/PhpSwitcher.swift b/phpmon-common/PHP/PhpSwitcher.swift index 213a237..8927d1e 100644 --- a/phpmon-common/PHP/PhpSwitcher.swift +++ b/phpmon-common/PHP/PhpSwitcher.swift @@ -27,7 +27,7 @@ class PhpSwitcher { from: brewPhpAlias.data(using: .utf8)! ).first! - print("When on your system, the `php` formula means version \(homebrewPackage.version)!") + Log.info("When on your system, the `php` formula means version \(homebrewPackage.version)!") } // MARK: - Properties @@ -100,7 +100,7 @@ class PhpSwitcher { versionsOnly.append(phpAlias) } - print("The PHP versions that were detected are: \(versionsOnly)") + Log.info("The PHP versions that were detected are: \(versionsOnly)") availablePhpVersions = versionsOnly diff --git a/phpmon-tests/Utility.swift b/phpmon-tests/Utility.swift index 218a459..ac55f18 100644 --- a/phpmon-tests/Utility.swift +++ b/phpmon-tests/Utility.swift @@ -19,7 +19,7 @@ class Utility { try FileManager.default.copyItem(at: bundleURL, to: targetURL) return targetURL } catch let error { - print("Unable to copy file: \(error)") + Log.err("Unable to copy file: \(error)") } } diff --git a/phpmon/Domain/Core/App+GlobalHotkey.swift b/phpmon/Domain/Core/App+GlobalHotkey.swift index 8f4f54c..bea998e 100644 --- a/phpmon/Domain/Core/App+GlobalHotkey.swift +++ b/phpmon/Domain/Core/App+GlobalHotkey.swift @@ -20,13 +20,13 @@ extension App { func loadGlobalHotkey() { // Make sure we can retrieve the hotkey from preferences guard let hotkey = Preferences.preferences[.globalHotkey] as? String else { - print("No global hotkey was saved in preferences. None set.") + Log.info("No global hotkey was saved in preferences. None set.") return } // Make sure we can parse the JSON into the desired format guard let keybindPref = GlobalKeybindPreference.fromJson(hotkey) else { - print("No global hotkey loaded, could not be parsed!") + Log.err("No global hotkey loaded, could not be parsed!") shortcutHotkey = nil return } diff --git a/phpmon/Domain/Core/AppDelegate+Notifications.swift b/phpmon/Domain/Core/AppDelegate+Notifications.swift index 3feff20..f848b57 100644 --- a/phpmon/Domain/Core/AppDelegate+Notifications.swift +++ b/phpmon/Domain/Core/AppDelegate+Notifications.swift @@ -18,11 +18,11 @@ extension AppDelegate { notificationCenter.delegate = self notificationCenter.requestAuthorization(options: [.alert], completionHandler: { granted, error in if !granted { - print("PHP Monitor does not have permission to show notifications.") + Log.warn("PHP Monitor does not have permission to show notifications.") } if let error = error { - print("PHP Monitor encounted an error determining notification permissions:") - print(error) + Log.err("PHP Monitor encounted an error determining notification permissions:") + Log.err(error) } }) } diff --git a/phpmon/Domain/Core/AppDelegate.swift b/phpmon/Domain/Core/AppDelegate.swift index 6729135..852839d 100644 --- a/phpmon/Domain/Core/AppDelegate.swift +++ b/phpmon/Domain/Core/AppDelegate.swift @@ -51,16 +51,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele */ var switcher: PhpSwitcher! = nil + var logger: Log = Log.shared + // MARK: - Initializer /** When the application initializes, create all singletons. */ override init() { - print("==================================") - print("PHP MONITOR by Nico Verbruggen") - print("Version \(App.version)") - print("==================================") + Log.shared.verbosity = .info + Log.info("==================================") + Log.info("PHP MONITOR by Nico Verbruggen") + Log.info("Version \(App.version)") + Log.info("==================================") self.sharedShell = Shell.user self.state = App.shared self.menu = MainMenu.shared diff --git a/phpmon/Domain/Core/Startup.swift b/phpmon/Domain/Core/Startup.swift index 987cf45..df35fcb 100644 --- a/phpmon/Domain/Core/Startup.swift +++ b/phpmon/Domain/Core/Startup.swift @@ -77,7 +77,7 @@ class Startup { if (!failed) { initializeSwitcher() - print("PHP Monitor has determined the application has successfully passed all checks.") + Log.info("PHP Monitor has determined the application has successfully passed all checks.") success() } } diff --git a/phpmon/Domain/Helpers/LocalNotification.swift b/phpmon/Domain/Helpers/LocalNotification.swift index 8bf0da2..0c391a3 100644 --- a/phpmon/Domain/Helpers/LocalNotification.swift +++ b/phpmon/Domain/Helpers/LocalNotification.swift @@ -25,7 +25,7 @@ class LocalNotification { let notificationCenter = UNUserNotificationCenter.current() notificationCenter.add(request) { (error) in if error != nil { - print(error!) + Log.err(error!) } } } diff --git a/phpmon/Domain/Helpers/PMWindowController.swift b/phpmon/Domain/Helpers/PMWindowController.swift index d6c8f89..9b26a14 100644 --- a/phpmon/Domain/Helpers/PMWindowController.swift +++ b/phpmon/Domain/Helpers/PMWindowController.swift @@ -30,7 +30,7 @@ class PMWindowController: NSWindowController, NSWindowDelegate { } deinit { - print("Window controller '\(windowName)' was deinitialized") + Log.perf("Window controller '\(windowName)' was deinitialized") } } diff --git a/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift index b473c6f..29faf62 100644 --- a/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift +++ b/phpmon/Domain/Integrations/Homebrew/HomebrewDiagnostics.swift @@ -35,11 +35,11 @@ class HomebrewDiagnostics { let tapAlias = Shell.pipe("\(Paths.brew) info shivammathur/php/php --json") if tapAlias.contains("brew tap shivammathur/php") || tapAlias.contains("Error") { - print("The user does not appear to have tapped: shivammathur/php") + Log.info("The user does not appear to have tapped: shivammathur/php") return false } else { - print("The user DOES have the following tapped: shivammathur/php") - print("Checking for `php` formula conflicts...") + Log.info("The user DOES have the following tapped: shivammathur/php") + Log.info("Checking for `php` formula conflicts...") let tapPhp = try! JSONDecoder().decode( [HomebrewPackage].self, @@ -47,22 +47,22 @@ class HomebrewDiagnostics { ).first! if tapPhp.version != PhpSwitcher.brewPhpVersion { - print("The `php` formula alias seems to be the different between the tap and core. This could be a problem!") - print("Determining whether both of these versions are installed...") + Log.warn("The `php` formula alias seems to be the different between the tap and core. This could be a problem!") + Log.info("Determining whether both of these versions are installed...") let bothInstalled = PhpSwitcher.shared.availablePhpVersions.contains(tapPhp.version) && PhpSwitcher.shared.availablePhpVersions.contains(PhpSwitcher.brewPhpVersion) if bothInstalled { - print("Both conflicting aliases seem to be installed, warning the user!") + Log.warn("Both conflicting aliases seem to be installed, warning the user!") } else { - print("Conflicting aliases are not both installed, seems fine!") + Log.info("Conflicting aliases are not both installed, seems fine!") } return bothInstalled } - print("All seems to be OK. No conflicts, both are PHP \(tapPhp.version).") + Log.info("All seems to be OK. No conflicts, both are PHP \(tapPhp.version).") return false } diff --git a/phpmon/Domain/Integrations/Valet/Valet.swift b/phpmon/Domain/Integrations/Valet/Valet.swift index 0759406..f42ff61 100644 --- a/phpmon/Domain/Integrations/Valet/Valet.swift +++ b/phpmon/Domain/Integrations/Valet/Valet.swift @@ -39,7 +39,7 @@ class Valet { public func startPreloadingSites() { if self.sites.count <= 10 { // Preload the sites and their drivers - print("Fewer than or 11 sites found, preloading list of sites...") + Log.info("Fewer than or 11 sites found, preloading list of sites...") self.reloadSites() } } @@ -50,17 +50,17 @@ class Valet { public func validateVersion() -> Void { if version == "UNKNOWN" { - return print("The Valet version could not be extracted... that does not bode well.") + return Log.warn("The Valet version could not be extracted... that does not bode well.") } if version.versionCompare(Constants.MinimumRecommendedValetVersion) == .orderedAscending { let version = version - print("Valet version \(version) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))") + Log.warn("Valet version \(version) is too old! (recommended: \(Constants.MinimumRecommendedValetVersion))") DispatchQueue.main.async { Alert.notify(message: "alert.min_valet_version.title".localized, info: "alert.min_valet_version.info".localized(version, Constants.MinimumRecommendedValetVersion)) } } else { - print("Valet version \(version) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))") + Log.info("Valet version \(version) is recent enough, OK (recommended: \(Constants.MinimumRecommendedValetVersion))") } } diff --git a/phpmon/Domain/Menu/MainMenu.swift b/phpmon/Domain/Menu/MainMenu.swift index 3d6ccfa..121d86e 100644 --- a/phpmon/Domain/Menu/MainMenu.swift +++ b/phpmon/Domain/Menu/MainMenu.swift @@ -55,31 +55,31 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { updatePhpVersionInStatusBar() - print("Determining broken PHP-FPM...") + Log.info("Determining broken PHP-FPM...") // Attempt to find out if PHP-FPM is broken let installation = PhpSwitcher.phpInstall installation.notifyAboutBrokenPhpFpm() // Set up the config watchers on launch (these are automatically updated via delegate methods if the user switches) - print("Setting up watchers...") + Log.info("Setting up watchers...") App.shared.handlePhpConfigWatcher() - print("Detecting applications...") + Log.info("Detecting applications...") // Attempt to load list of applications App.shared.detectedApplications = Application.detectPresetApplications() let appNames = App.shared.detectedApplications.map { app in return app.name } - print("Detected applications: \(appNames)") + Log.info("Detected applications: \(appNames)") // Load the global hotkey App.shared.loadGlobalHotkey() // Attempt to find out more info about Valet - print("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version)") + Log.info("PHP Monitor has extracted the version number of Valet: \(Valet.shared.version)") Valet.shared.validateVersion() Valet.shared.startPreloadingSites() - print("PHP Monitor is ready to serve!") + Log.info("PHP Monitor is ready to serve!") // Schedule a request to fetch the PHP version every 60 seconds DispatchQueue.main.async { [self] in @@ -232,14 +232,14 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { @objc func reloadPhpMonitorMenuInBackground() { waitAndExecute { // This automatically reloads the menu - print("Reloading information about the PHP installation (in the background)...") + Log.info("Reloading information about the PHP installation (in the background)...") } } @objc func reloadPhpMonitorMenu() { waitAndExecute { // This automatically reloads the menu - print("Reloading information about the PHP installation...") + Log.info("Reloading information about the PHP installation...") } completion: { // Add a slight delay to make sure it loads the new menu DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { @@ -378,13 +378,13 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate { DispatchQueue.main.async { window?.addToConsole(string) } - print("\(string.trimmingCharacters(in: .newlines))") + Log.perf("\(string.trimmingCharacters(in: .newlines))") }, didReceiveStdErrData: { string in DispatchQueue.main.async { window?.addToConsole(string) } - print("\(string.trimmingCharacters(in: .newlines))") + Log.perf("\(string.trimmingCharacters(in: .newlines))") } ) diff --git a/phpmon/Domain/Preferences/Preferences.swift b/phpmon/Domain/Preferences/Preferences.swift index 7897c06..45c8bff 100644 --- a/phpmon/Domain/Preferences/Preferences.swift +++ b/phpmon/Domain/Preferences/Preferences.swift @@ -55,7 +55,7 @@ class Preferences { if UserDefaults.standard.bool(forKey: PreferenceName.wasLaunchedBefore.rawValue) { return } - print("Saving first-time preferences!") + Log.info("Saving first-time preferences!") UserDefaults.standard.setValue(true, forKey: PreferenceName.wasLaunchedBefore.rawValue) UserDefaults.standard.synchronize() } diff --git a/phpmon/Domain/Preferences/PrefsVC.swift b/phpmon/Domain/Preferences/PrefsVC.swift index b2c872b..a1aaaab 100644 --- a/phpmon/Domain/Preferences/PrefsVC.swift +++ b/phpmon/Domain/Preferences/PrefsVC.swift @@ -110,6 +110,6 @@ class PrefsVC: NSViewController { // MARK: - Deinitialization deinit { - print("VC deallocated") + Log.perf("PrefsVC deallocated") } } diff --git a/phpmon/Domain/Preferences/PrefsWC.swift b/phpmon/Domain/Preferences/PrefsWC.swift index f2ef5b9..6cd24ba 100644 --- a/phpmon/Domain/Preferences/PrefsWC.swift +++ b/phpmon/Domain/Preferences/PrefsWC.swift @@ -29,7 +29,7 @@ class PrefsWC: PMWindowController { if let vc = contentViewController as? PrefsVC { if vc.listeningForHotkeyView != nil { if event.keyCode == Keys.Escape || event.keyCode == Keys.Space { - print("A blacklisted key was pressed, canceling listen") + Log.info("A blacklisted key was pressed, canceling listen!") vc.listeningForHotkeyView = nil } else { vc.listeningForHotkeyView!.updateShortcut(event) diff --git a/phpmon/Domain/Progress/ProgressWindow.swift b/phpmon/Domain/Progress/ProgressWindow.swift index 15613c1..0030f93 100644 --- a/phpmon/Domain/Progress/ProgressWindow.swift +++ b/phpmon/Domain/Progress/ProgressWindow.swift @@ -56,7 +56,7 @@ class ProgressWindowController: NSWindowController, NSWindowDelegate { } deinit { - // print("Deinitializing Progress Window Controller") + Log.perf("Deinitializing ProgressWindowController") } } @@ -70,7 +70,7 @@ class ProgressViewController: NSViewController { @IBOutlet weak var imageViewType: NSImageView! deinit { - // print("Deinitializing Progress View Controller") + Log.perf("Deinitializing ProgressViewController") } } diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift index b03fad1..b56d4c6 100644 --- a/phpmon/Domain/SiteList/SiteListVC.swift +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -268,6 +268,6 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { // MARK: - Deinitialization deinit { - print("VC deallocated") + Log.perf("SiteListVC deallocated") } } diff --git a/phpmon/Domain/Watcher/App+ConfigWatch.swift b/phpmon/Domain/Watcher/App+ConfigWatch.swift index 6e170f2..ae710c9 100644 --- a/phpmon/Domain/Watcher/App+ConfigWatch.swift +++ b/phpmon/Domain/Watcher/App+ConfigWatch.swift @@ -11,16 +11,16 @@ import Foundation extension App { func startWatcher(_ url: URL) { - print("No watcher currently active...") + Log.info("No watcher currently active...") self.watcher = PhpConfigWatcher(for: url) self.watcher.didChange = { url in - print("Something has changed in: \(url)") + Log.info("Something has changed in: \(url)") // Check if the watcher has last updated the menu less than 0.75s ago let distance = self.watcher.lastUpdate?.distance(to: Date().timeIntervalSince1970) if distance == nil || distance != nil && distance! > 0.75 { - print("Refreshing menu...") + Log.info("Refreshing menu...") MainMenu.shared.reloadPhpMonitorMenuInBackground() self.watcher.lastUpdate = Date().timeIntervalSince1970 } @@ -39,7 +39,7 @@ extension App { if self.watcher.url != url || forceReload { self.watcher.disable() self.watcher = nil - print("Watcher has stopped watching files. Starting new one...") + Log.info("Watcher has stopped watching files. Starting new one...") startWatcher(url) } } diff --git a/phpmon/Domain/Watcher/PhpConfigWatcher.swift b/phpmon/Domain/Watcher/PhpConfigWatcher.swift index cd5e6df..e97cfe5 100644 --- a/phpmon/Domain/Watcher/PhpConfigWatcher.swift +++ b/phpmon/Domain/Watcher/PhpConfigWatcher.swift @@ -40,8 +40,8 @@ class PhpConfigWatcher { self.addWatcher(for: self.url.appendingPathComponent("conf.d/\(file)"), eventMask: .write) } - print("A watcher exists for the following config paths:") - print(self.watchers.map({ watcher in + Log.info("A watcher exists for the following config paths:") + Log.info(self.watchers.map({ watcher in return watcher.url.relativePath })) } @@ -52,14 +52,14 @@ class PhpConfigWatcher { } func disable() { - print("Turning off existing watchers...") + Log.info("Turning off existing watchers...") self.watchers.forEach { (watcher) in watcher.stopMonitoring() } } deinit { - print("An existing config watcher has been deinitialized.") + Log.perf("A PhpConfigWatcher has been deinitialized.") } }