From a3a002a2d3ee76d0eee0771a3fc99cf4df063827 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Sat, 26 Jun 2021 13:38:45 +0200 Subject: [PATCH] feat: removed os.log and moved to NextLog --- Kit/helpers.swift | 19 +--------------- Kit/module/module.swift | 19 ++++++++-------- Kit/module/reader.swift | 18 +++++++-------- Kit/module/widget.swift | 14 +++++++----- Modules/Battery/readers.swift | 3 +-- Modules/CPU/readers.swift | 37 +++++++++++++++---------------- Modules/Disk/readers.swift | 13 +++++------ Modules/Fans/readers.swift | 3 +-- Modules/GPU/reader.swift | 9 ++++---- Modules/Net/readers.swift | 17 +++++++------- Modules/RAM/readers.swift | 9 ++++---- Modules/Sensors/readers.swift | 1 - SMC/smc.swift | 1 + Stats.xcodeproj/project.pbxproj | 4 ++++ Stats/AppDelegate.swift | 8 +++---- Stats/Supporting Files/Info.plist | 2 +- Stats/Views/AppSettings.swift | 5 ++--- Stats/Views/Dashboard.swift | 1 - Stats/Views/Update.swift | 1 - Stats/helpers.swift | 17 +++++++------- 20 files changed, 88 insertions(+), 113 deletions(-) diff --git a/Kit/helpers.swift b/Kit/helpers.swift index d77dbb46..2c23b073 100644 --- a/Kit/helpers.swift +++ b/Kit/helpers.swift @@ -11,7 +11,6 @@ // swiftlint:disable file_length import Cocoa -import os.log import ServiceManagement public struct LaunchAtLogin { @@ -581,22 +580,6 @@ public class ColorView: NSView { } } -public struct Log: TextOutputStream { - public static var log: Log = Log() - - public func write(_ string: String) { - let fm = FileManager.default - let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("log.txt") - if let handle = try? FileHandle(forWritingTo: log) { - handle.seekToEndOfFile() - handle.write(string.data(using: .utf8)!) - handle.closeFile() - } else { - try? string.data(using: .utf8)?.write(to: log) - } - } -} - public func localizedString(_ key: String, _ params: String..., comment: String = "") -> String { var string = NSLocalizedString(key, comment: comment) if !params.isEmpty { @@ -828,7 +811,7 @@ public func process(path: String, arguments: [String]) -> String? { do { try task.run() } catch let error { - os_log(.error, log: .default, "system_profiler SPMemoryDataType: %s", "\(error.localizedDescription)") + debug("system_profiler SPMemoryDataType: \(error.localizedDescription)") return nil } diff --git a/Kit/module/module.swift b/Kit/module/module.swift index 0e36e769..ecb1bf7d 100644 --- a/Kit/module/module.swift +++ b/Kit/module/module.swift @@ -7,7 +7,6 @@ // import Cocoa -import os.log public protocol Module_p { var available: Bool { get } @@ -78,20 +77,20 @@ open class Module: Module_p { private var popup: PopupWindow? = nil private var popupView: Popup_p? = nil - private let log: OSLog + private let log: NextLog private var readers: [Reader_p] = [] public init(popup: Popup_p?, settings: Settings_v?) { self.config = module_c(in: Bundle(for: type(of: self)).path(forResource: "config", ofType: "plist")!) - self.log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: self.config.name) + self.log = NextLog.shared.copy(category: self.config.name) self.settingsView = settings self.popupView = popup self.available = self.isAvailable() self.enabled = Store.shared.bool(key: "\(self.config.name)_state", defaultValue: self.config.defaultState) if !self.available { - os_log(.debug, log: log, "Module is not available") + debug("Module is not available", log: self.log) if self.enabled { self.enabled = false @@ -110,7 +109,7 @@ open class Module: Module_p { if self.config.widgetsConfig.count != 0 { self.initWidgets() } else { - os_log(.debug, log: log, "Module started without widget") + debug("Module started without widget", log: self.log) } self.settings = Settings(config: &self.config, widgets: &self.widgets, enabled: self.enabled, moduleSettings: self.settingsView) @@ -151,7 +150,7 @@ open class Module: Module_p { $0.terminate() } self.widgets.forEach{ $0.disable() } - os_log(.debug, log: log, "Module terminated") + debug("Module terminated", log: self.log) } // function to call before module terminate @@ -168,7 +167,7 @@ open class Module: Module_p { reader.start() } self.widgets.forEach{ $0.enable() } - os_log(.debug, log: log, "Module enabled") + debug("Module enabled", log: self.log) } // set module state to disabled @@ -180,7 +179,7 @@ open class Module: Module_p { self.readers.forEach{ $0.stop() } self.widgets.forEach{ $0.disable() } self.popup?.setIsVisible(false) - os_log(.debug, log: log, "Module disabled") + debug("Module disabled", log: self.log) } // toggle module state @@ -195,13 +194,13 @@ open class Module: Module_p { // add reader to module. If module is enabled will fire a read function and start a reader public func addReader(_ reader: Reader_p) { self.readers.append(reader) - os_log(.debug, log: log, "Reader %s was added", "\(reader.self)") + debug("\(reader.self) was added", log: self.log) } // handler for reader, calls when main reader is ready, and return first value public func readyHandler() { self.widgets.forEach{ $0.enable() } - os_log(.debug, log: log, "Reader report readiness") + debug("Reader report readiness", log: self.log) } // replace a popup view diff --git a/Kit/module/reader.swift b/Kit/module/reader.swift index 34289a88..5e2dc4fe 100644 --- a/Kit/module/reader.swift +++ b/Kit/module/reader.swift @@ -11,7 +11,6 @@ import Cocoa import Repeat -import os.log public protocol value_t { var widgetValue: Double { get } @@ -47,7 +46,9 @@ public protocol ReaderInternal_p { } open class Reader: ReaderInternal_p { - public var log: OSLog + public var log: NextLog { + return NextLog.shared.copy(category: "\(String(describing: self))") + } public var value: T? public var interval: Double? = nil public var defaultInterval: Double = 1 @@ -67,12 +68,11 @@ open class Reader: ReaderInternal_p { private var history: [T]? = [] public init(popup: Bool = false) { - self.log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "\(T.self)") self.popup = popup self.setup() - os_log(.debug, log: self.log, "Successfully initialize reader") + debug("Successfully initialize reader", log: self.log) } public func initStoreValues(title: String) { @@ -91,14 +91,14 @@ open class Reader: ReaderInternal_p { if self.value == nil && value != nil { self.ready = true self.readyCallback() - os_log(.debug, log: self.log, "Reader is ready") + debug("Reader is ready", log: self.log) } else if self.value == nil && value != nil { if self.nilCallbackCounter > 5 { - os_log(.error, log: self.log, "Callback receive nil value more than 5 times. Please check this reader!") + error("Callback receive nil value more than 5 times. Please check this reader!", log: self.log) self.stop() return } else { - os_log(.debug, log: self.log, "Restarting initial read") + debug("Restarting initial read", log: self.log) self.nilCallbackCounter += 1 self.read() return @@ -134,7 +134,7 @@ open class Reader: ReaderInternal_p { if let interval = self.interval, self.repeatTask == nil { if !self.popup && !self.optional { - os_log(.debug, log: self.log, "Set up update interval: %.0f sec", interval) + debug("Set up update interval: \(Int(interval)) sec", log: self.log) } self.repeatTask = Repeater.init(interval: .seconds(interval), observer: { _ in @@ -165,7 +165,7 @@ open class Reader: ReaderInternal_p { } public func setInterval(_ value: Int) { - os_log(.debug, log: self.log, "Set update interval: %d sec", value) + debug("Set update interval: \(Int(value)) sec", log: self.log) self.interval = Double(value) self.repeatTask?.reset(.seconds(Double(value)), restart: true) } diff --git a/Kit/module/widget.swift b/Kit/module/widget.swift index 376b2ca8..c9dabf72 100644 --- a/Kit/module/widget.swift +++ b/Kit/module/widget.swift @@ -10,7 +10,6 @@ // import Cocoa -import os.log public enum widget_t: String { case unknown = "" @@ -158,7 +157,9 @@ public class Widget { private var config: NSDictionary = NSDictionary() private var menuBarItem: NSStatusItem? = nil - private let log: OSLog + public var log: NextLog { + return NextLog.shared.copy(category: self.module) + } private var list: [widget_t] { get { @@ -176,12 +177,13 @@ public class Widget { self.preview = preview self.item = item self.defaultWidget = defaultWidget - self.log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: self.module) self.item.widthHandler = { [weak self] value in if let s = self, let item = s.menuBarItem, item.length != value { item.length = value - os_log(.debug, log: s.log, "widget %s change width to %.2f", "\(s.type)", value) + if let this = self { + debug("widget \(s.type) change width to \(Double(value).rounded(toPlaces: 2))", log: this.log) + } } } } @@ -206,7 +208,7 @@ public class Widget { self.menuBarItem?.button?.sendAction(on: [.leftMouseDown, .rightMouseDown]) }) - os_log(.debug, log: log, "widget %s enabled", self.type.rawValue) + debug("widget \(self.type.rawValue) enabled", log: self.log) } // remove item from the menu bar @@ -215,7 +217,7 @@ public class Widget { NSStatusBar.system.removeStatusItem(item) } self.menuBarItem = nil - os_log(.debug, log: log, "widget %s disabled", self.type.rawValue) + debug("widget \(self.type.rawValue) disabled", log: self.log) } // toggle the widget diff --git a/Modules/Battery/readers.swift b/Modules/Battery/readers.swift index 9d1b69cb..5502e625 100644 --- a/Modules/Battery/readers.swift +++ b/Modules/Battery/readers.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log internal class UsageReader: Reader { private var service: io_connect_t = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSmartBattery")) @@ -210,7 +209,7 @@ public class ProcessReader: Reader<[TopProcess]> { do { try self.task.run() } catch let error { - os_log(.error, log: log, "run Battery process reader %s", "\(error)") + debug("run Battery process reader \(error)", log: self.log) } } else if self.paused { self.paused = !self.task.resume() diff --git a/Modules/CPU/readers.swift b/Modules/CPU/readers.swift index c3061486..9e956546 100644 --- a/Modules/CPU/readers.swift +++ b/Modules/CPU/readers.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log internal class LoadReader: Reader { private var cpuInfo: processor_info_array_t! @@ -98,7 +97,7 @@ internal class LoadReader: Reader { self.cpuInfo = nil self.numCpuInfo = 0 } else { - os_log(.error, log: log, "host_processor_info(): %s", "\((String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error"))") + error("host_processor_info(): \(String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error")", log: self.log) } let cpuInfo = hostCPULoadInfo() @@ -143,7 +142,7 @@ internal class LoadReader: Reader { } } if result != KERN_SUCCESS { - os_log(.error, log: log, "kern_result_t: %s", "\(result)") + error("kern_result_t: \(result)", log: self.log) return nil } @@ -186,8 +185,8 @@ public class ProcessReader: Reader<[TopProcess]> { do { try task.run() - } catch let error { - os_log(.error, log: log, "error read ps: %s", "\(error.localizedDescription)") + } catch let err { + error("error read ps: \(err.localizedDescription)", log: self.log) return } @@ -286,33 +285,33 @@ public class FrequencyReader: Reader { self.bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL) if self.bundle == nil { - os_log(.error, log: log, "IntelPowerGadget framework not found") + error("IntelPowerGadget framework not found", log: self.log) return } if !CFBundleLoadExecutable(self.bundle) { - os_log(.error, log: log, "failed to load IPG framework") + error("failed to load IPG framework", log: self.log) return } guard let PG_InitializePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Initialize" as CFString) else { - os_log(.error, log: log, "failed to find PG_Initialize") + error("failed to find PG_Initialize", log: self.log) return } guard let PG_ShutdownPointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_Shutdown" as CFString) else { - os_log(.error, log: log, "failed to find PG_Shutdown") + error("failed to find PG_Shutdown", log: self.log) return } guard let PG_ReadSamplePointer = CFBundleGetFunctionPointerForName(self.bundle, "PG_ReadSample" as CFString) else { - os_log(.error, log: log, "failed to find PG_ReadSample") + error("failed to find PG_ReadSample", log: self.log) return } guard let PGSample_GetIAFrequencyPointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_GetIAFrequency" as CFString) else { - os_log(.error, log: log, "failed to find PGSample_GetIAFrequency") + error("failed to find PGSample_GetIAFrequency", log: self.log) return } guard let PGSample_ReleasePointer = CFBundleGetFunctionPointerForName(self.bundle, "PGSample_Release" as CFString) else { - os_log(.error, log: log, "failed to find PGSample_Release") + error("failed to find PGSample_Release", log: self.log) return } @@ -324,7 +323,7 @@ public class FrequencyReader: Reader { if let initialize = self.PG_Initialize { if !initialize() { - os_log(.error, log: log, "IPG initialization failed") + error("IPG initialization failed", log: self.log) return } } @@ -339,7 +338,7 @@ public class FrequencyReader: Reader { public override func terminate() { if let shutdown = self.PG_Shutdown { if !shutdown() { - os_log(.error, log: log, "IPG shutdown failed") + error("IPG shutdown failed", log: self.log) return } } @@ -361,7 +360,7 @@ public class FrequencyReader: Reader { self.terminate() if let initialize = self.PG_Initialize { if !initialize() { - os_log(.error, log: log, "IPG initialization failed") + error("IPG initialization failed", log: self.log) return } } @@ -377,7 +376,7 @@ public class FrequencyReader: Reader { // first sample initlialization if self.sample == 0 { if !self.PG_ReadSample!(0, &self.sample) { - os_log(.error, log: log, "read self.sample failed") + error("read self.sample failed", log: self.log) } return } @@ -386,7 +385,7 @@ public class FrequencyReader: Reader { if !self.PG_ReadSample!(0, &local) { self.reconnect() - os_log(.error, log: log, "read local sample failed") + error("read local sample failed", log: self.log) return } @@ -396,13 +395,13 @@ public class FrequencyReader: Reader { defer { if !self.PGSample_Release!(self.sample) { - os_log(.error, log: log, "release self.sample failed") + error("release self.sample failed", log: self.log) } self.sample = local } if !self.PGSample_GetIAFrequency!(self.sample, local, &value, &min, &max) { - os_log(.error, log: log, "read frequency failed") + error("read frequency failed", log: self.log) return } diff --git a/Modules/Disk/readers.swift b/Modules/Disk/readers.swift index 825d2b93..b4021b57 100644 --- a/Modules/Disk/readers.swift +++ b/Modules/Disk/readers.swift @@ -13,7 +13,6 @@ import Cocoa import Kit import IOKit import Darwin -import os.log internal class CapacityReader: Reader { internal var list: Disks = Disks() @@ -24,7 +23,7 @@ internal class CapacityReader: Reader { let paths = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys)! guard let session = DASessionCreate(kCFAllocatorDefault) else { - os_log(.error, log: log, "cannot create a DASessionCreate()") + error("cannot create main DASessionCreate()", log: self.log) return } @@ -82,8 +81,8 @@ internal class CapacityReader: Reader { return capacity } } - } catch { - os_log(.error, log: log, "error retrieving free space #1: %s", "\(error.localizedDescription)") + } catch let err { + error("error retrieving free space #1: \(err.localizedDescription)", log: self.log) } do { @@ -91,8 +90,8 @@ internal class CapacityReader: Reader { if let freeSpace = (systemAttributes[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value { return freeSpace } - } catch { - os_log(.error, log: log, "error retrieving free space #2: %s", "\(error.localizedDescription)") + } catch let err { + error("error retrieving free space #2: \(err.localizedDescription)", log: self.log) } return 0 @@ -116,7 +115,7 @@ internal class ActivityReader: Reader { let paths = FileManager.default.mountedVolumeURLs(includingResourceValuesForKeys: keys)! guard let session = DASessionCreate(kCFAllocatorDefault) else { - os_log(.error, log: log, "cannot create a DASessionCreate()") + error("cannot create a DASessionCreate()", log: self.log) return } diff --git a/Modules/Fans/readers.swift b/Modules/Fans/readers.swift index 994c659d..bfc5b280 100644 --- a/Modules/Fans/readers.swift +++ b/Modules/Fans/readers.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log internal class FansReader: Reader<[Fan]> { internal var list: [Fan] = [] @@ -22,7 +21,7 @@ internal class FansReader: Reader<[Fan]> { guard let count = SMC.shared.getValue("FNum") else { return } - os_log(.debug, log: self.log, "Found %.0f fans", count) + debug("Found \(Int(count)) fans", log: self.log) for i in 0.. { devices.forEach { (dict: NSDictionary) in guard let deviceID = dict["device-id"] as? Data, let vendorID = dict["vendor-id"] as? Data else { - os_log(.error, log: log, "device-id or vendor-id not found") + error("device-id or vendor-id not found", log: self.log) return } let pci = "0x" + Data([deviceID[1], deviceID[0], vendorID[1], vendorID[0]]).map { String(format: "%02hhX", $0) }.joined().lowercased() guard let modelData = dict["model"] as? Data, let modelName = String(data: modelData, encoding: .ascii) else { - os_log(.error, log: log, "GPU model not found") + error("GPU model not found", log: self.log) return } let model = modelName.replacingOccurrences(of: "\0", with: "") @@ -71,12 +70,12 @@ internal class InfoReader: Reader { for (index, accelerator) in accelerators.enumerated() { guard let IOClass = accelerator.object(forKey: "IOClass") as? String else { - os_log(.error, log: log, "IOClass not found") + error("IOClass not found", log: self.log) return } guard let stats = accelerator["PerformanceStatistics"] as? [String: Any] else { - os_log(.error, log: log, "PerformanceStatistics not found") + error("PerformanceStatistics not found", log: self.log) return } diff --git a/Modules/Net/readers.swift b/Modules/Net/readers.swift index f50a7364..0cb36a09 100644 --- a/Modules/Net/readers.swift +++ b/Modules/Net/readers.swift @@ -13,7 +13,6 @@ import Cocoa import Kit import SystemConfiguration import Reachability -import os.log import CoreWLAN struct ipResponse: Decodable { @@ -54,8 +53,8 @@ internal class UsageReader: Reader { do { self.reachability = try Reachability() try self.reachability!.startNotifier() - } catch let error { - os_log(.error, log: log, "initialize Reachability error %s", "\(error)") + } catch let err { + error("initialize Reachability error \(err)", log: self.log) } self.reachability!.whenReachable = { _ in @@ -145,8 +144,8 @@ internal class UsageReader: Reader { do { try task.run() - } catch let error { - os_log(.error, log: log, "read bandwidth from processes %s", "\(error)") + } catch let err { + error("read bandwidth from processes: \(err)", log: self.log) return (0, 0) } @@ -241,8 +240,8 @@ internal class UsageReader: Reader { self.usage.raddr.v4 = value } } - } catch let error { - os_log(.error, log: log, "get public ipv4 %s", "\(error)") + } catch let err { + error("get public ipv4: \(err)", log: self.log) } do { @@ -252,8 +251,8 @@ internal class UsageReader: Reader { self.usage.raddr.v6 = value } } - } catch let error { - os_log(.error, log: log, "get public ipv6 %s", "\(error)") + } catch let err { + error("get public ipv6: \(err)", log: self.log) } } diff --git a/Modules/RAM/readers.swift b/Modules/RAM/readers.swift index c06d017b..204c81aa 100644 --- a/Modules/RAM/readers.swift +++ b/Modules/RAM/readers.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log internal class UsageReader: Reader { public var totalSize: Double = 0 @@ -32,7 +31,7 @@ internal class UsageReader: Reader { } self.totalSize = 0 - os_log(.error, log: log, "host_info(): %s", "\((String(cString: mach_error_string(kerr), encoding: String.Encoding.ascii) ?? "unknown error"))") + error("host_info(): \(String(cString: mach_error_string(kerr), encoding: String.Encoding.ascii) ?? "unknown error")", log: self.log) } public override func read() { @@ -90,7 +89,7 @@ internal class UsageReader: Reader { return } - os_log(.error, log: log, "host_statistics64(): %s", "\((String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error"))") + error("host_statistics64(): \(String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error")", log: self.log) } } @@ -129,8 +128,8 @@ public class ProcessReader: Reader<[TopProcess]> { do { try task.run() - } catch let error { - os_log(.error, log: log, "top(): %s", "\(error.localizedDescription)") + } catch let err { + error("top(): \(err.localizedDescription)", log: self.log) return } diff --git a/Modules/Sensors/readers.swift b/Modules/Sensors/readers.swift index d0b30c7c..70814d5b 100644 --- a/Modules/Sensors/readers.swift +++ b/Modules/Sensors/readers.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log import IOKit.hid internal class SensorsReader: Reader<[Sensor_t]> { diff --git a/SMC/smc.swift b/SMC/smc.swift index 8f0f2132..75a095d0 100644 --- a/SMC/smc.swift +++ b/SMC/smc.swift @@ -8,6 +8,7 @@ // // Copyright © 2021 Serhiy Mytrovtsiy. All rights reserved. // +// swiftlint:disable file_length import Foundation import IOKit diff --git a/Stats.xcodeproj/project.pbxproj b/Stats.xcodeproj/project.pbxproj index 7b819cef..fa5f7edd 100644 --- a/Stats.xcodeproj/project.pbxproj +++ b/Stats.xcodeproj/project.pbxproj @@ -67,6 +67,7 @@ 9A65654A253F20EF0096B607 /* settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A656549253F20EF0096B607 /* settings.swift */; }; 9A656562253F788A0096B607 /* popup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A656561253F788A0096B607 /* popup.swift */; }; 9A6CFC0122A1C9F5001E782D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9A6CFC0022A1C9F5001E782D /* Assets.xcassets */; }; + 9A6EEBBE2685259500897371 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A6EEBBD2685259500897371 /* Logger.swift */; }; 9A81C74D24499C7000825D92 /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A81C74B24499C7000825D92 /* AppSettings.swift */; }; 9A81C74E24499C7000825D92 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A81C74C24499C7000825D92 /* Settings.swift */; }; 9A81C75D2449A41400825D92 /* RAM.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A81C7562449A41400825D92 /* RAM.framework */; }; @@ -368,6 +369,7 @@ 9A656549253F20EF0096B607 /* settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = settings.swift; sourceTree = ""; }; 9A656561253F788A0096B607 /* popup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = popup.swift; sourceTree = ""; }; 9A6CFC0022A1C9F5001E782D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 9A6EEBBD2685259500897371 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; 9A81C74B24499C7000825D92 /* AppSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = ""; }; 9A81C74C24499C7000825D92 /* Settings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; 9A81C7562449A41400825D92 /* RAM.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RAM.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -766,6 +768,7 @@ 9A2848042666AB2F00EC1F6D /* Charts.swift */, 9A2848032666AB2F00EC1F6D /* SystemKit.swift */, 9A2848072666AB3000EC1F6D /* Updater.swift */, + 9A6EEBBD2685259500897371 /* Logger.swift */, ); path = plugins; sourceTree = ""; @@ -1422,6 +1425,7 @@ 9A2847642666AA2700EC1F6D /* Battery.swift in Sources */, 9A28480B2666AB3000EC1F6D /* Charts.swift in Sources */, 9A2847632666AA2700EC1F6D /* Mini.swift in Sources */, + 9A6EEBBE2685259500897371 /* Logger.swift in Sources */, 9A2847602666AA2700EC1F6D /* NetworkChart.swift in Sources */, 9A2847792666AA5000EC1F6D /* module.swift in Sources */, 9A2847662666AA2700EC1F6D /* Speed.swift in Sources */, diff --git a/Stats/AppDelegate.swift b/Stats/AppDelegate.swift index 07573135..668a3754 100755 --- a/Stats/AppDelegate.swift +++ b/Stats/AppDelegate.swift @@ -7,7 +7,6 @@ // import Cocoa -import os.log import Kit @@ -31,7 +30,6 @@ var modules: [Module] = [ Network(), Battery() ] -var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Stats") class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate { internal let settingsWindow: SettingsWindow = SettingsWindow() @@ -53,7 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele self.defaultValues() self.updateCron() - os_log(.info, log: log, "Stats started in %.4f seconds", startingPoint.timeIntervalSinceNow * -1) + info("Stats started in \((startingPoint.timeIntervalSinceNow * -1).rounded(toPlaces: 4)) seconds") } func applicationWillTerminate(_ aNotification: Notification) { @@ -75,7 +73,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) { if let uri = notification.userInfo?["url"] as? String { - os_log(.debug, log: log, "Downloading new version of app...") + debug("Downloading new version of app...") if let url = URL(string: uri) { updater.download(url, doneHandler: { path in updater.install(path: path) @@ -93,7 +91,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele guard let updateInterval = AppUpdateInterval(rawValue: Store.shared.string(key: "update-interval", defaultValue: AppUpdateInterval.atStart.rawValue)) else { return } - os_log(.debug, log: log, "Application update interval is '%s'", "\(updateInterval.rawValue)") + debug("Application update interval is '\(updateInterval.rawValue)'") switch updateInterval { case .oncePerDay: self.updateActivity.interval = 60 * 60 * 24 diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist index 4692997a..a527d5e6 100755 --- a/Stats/Supporting Files/Info.plist +++ b/Stats/Supporting Files/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 283 + 284 Description Simple macOS system monitor in your menu bar LSApplicationCategoryType diff --git a/Stats/Views/AppSettings.swift b/Stats/Views/AppSettings.swift index e0703fa7..a9a25636 100644 --- a/Stats/Views/AppSettings.swift +++ b/Stats/Views/AppSettings.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log class ApplicationSettings: NSScrollView { private var updateIntervalValue: String { @@ -253,12 +252,12 @@ class ApplicationSettings: NSScrollView { @objc func updateAction(_ sender: NSObject) { updater.check { result, error in if error != nil { - os_log(.error, log: log, "error updater.check(): %s", "\(error!.localizedDescription)") + debug("error updater.check(): \(error!.localizedDescription)") return } guard error == nil, let version: version_s = result else { - os_log(.error, log: log, "download error(): %s", "\(error!.localizedDescription)") + debug("download error(): \(error!.localizedDescription)") return } diff --git a/Stats/Views/Dashboard.swift b/Stats/Views/Dashboard.swift index 2226a7ce..a9d21a71 100644 --- a/Stats/Views/Dashboard.swift +++ b/Stats/Views/Dashboard.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log class Dashboard: NSScrollView { private var uptimeField: NSTextField? = nil diff --git a/Stats/Views/Update.swift b/Stats/Views/Update.swift index 4c56a075..e708a8a8 100644 --- a/Stats/Views/Update.swift +++ b/Stats/Views/Update.swift @@ -11,7 +11,6 @@ import Cocoa import Kit -import os.log class UpdateWindow: NSWindow, NSWindowDelegate { private let viewController: UpdateViewController = UpdateViewController() diff --git a/Stats/helpers.swift b/Stats/helpers.swift index d5585b8c..e7c63018 100644 --- a/Stats/helpers.swift +++ b/Stats/helpers.swift @@ -11,14 +11,13 @@ import Cocoa import Kit -import os.log extension AppDelegate { internal func parseArguments() { let args = CommandLine.arguments if args.contains("--reset") { - os_log(.debug, log: log, "Receive --reset argument. Reseting store (UserDefaults)...") + debug("Receive --reset argument. Reseting store (UserDefaults)...") Store.shared.reset() } @@ -40,7 +39,7 @@ extension AppDelegate { asyncShell("/usr/bin/hdiutil detach \(mountPath)") asyncShell("/bin/rm -rf \(mountPath)") - os_log(.debug, log: log, "DMG was unmounted and mountPath deleted") + debug("DMG was unmounted and mountPath deleted") } } @@ -48,7 +47,7 @@ extension AppDelegate { if args.indices.contains(dmgIndex+1) { asyncShell("/bin/rm -rf \(args[dmgIndex+1])") - os_log(.debug, log: log, "DMG was deleted") + debug("DMG was deleted") } } } @@ -59,7 +58,7 @@ extension AppDelegate { if !Store.shared.exist(key: key) { Store.shared.reset() - os_log(.debug, log: log, "Previous version not detected. Current version (%s) set", currentVersion) + debug("Previous version not detected. Current version (\(currentVersion) set") } else { let prevVersion = Store.shared.string(key: key, defaultValue: "") if prevVersion == currentVersion { @@ -74,7 +73,7 @@ extension AppDelegate { ) } - os_log(.debug, log: log, "Detected previous version %s. Current version (%s) set", prevVersion, currentVersion) + debug("Detected previous version \(prevVersion). Current version (\(currentVersion) set") } Store.shared.set(key: key, value: currentVersion) @@ -99,18 +98,18 @@ extension AppDelegate { internal func checkForNewVersion() { updater.check { result, error in if error != nil { - os_log(.error, log: log, "error updater.check(): %s", "\(error!.localizedDescription)") + debug("error updater.check(): \(error!.localizedDescription)") return } guard error == nil, let version: version_s = result else { - os_log(.error, log: log, "download error(): %s", "\(error!.localizedDescription)") + debug("download error(): \(error!.localizedDescription)") return } DispatchQueue.main.async(execute: { if version.newest { - os_log(.debug, log: log, "show update window because new version of app found: %s", "\(version.latest)") + debug("show update window because new version of app found: \(version.latest)") self.updateNotification.identifier = "new-version-\(version.latest)" self.updateNotification.title = localizedString("New version available")