Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Sep 22, 2024
1 parent 2996468 commit bc31c26
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 65 deletions.
1 change: 0 additions & 1 deletion Ice/Bridging/Bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Cocoa
import OSLog

/// A namespace for bridged functionality.
enum Bridging { }
Expand Down
1 change: 0 additions & 1 deletion Ice/ControlItem/ControlItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// A status item that controls a section in the menu bar.
@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/Events/EventManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// Manager for the various event monitors maintained by the app.
@MainActor
Expand Down
8 changes: 1 addition & 7 deletions Ice/Hotkeys/Hotkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Combine
import OSLog

/// A combination of a key and modifiers that can be used to
/// trigger actions on system-wide key-up or key-down events.
Expand Down Expand Up @@ -91,7 +90,7 @@ extension Hotkey {
return
}
guard let appState else {
logError(to: .hotkey, "Error invalidating hotkey: Missing AppState")
logError("Error invalidating hotkey: Missing AppState")
return
}
defer {
Expand Down Expand Up @@ -141,8 +140,3 @@ extension Hotkey: Hashable {
hasher.combine(action)
}
}

// MARK: - Logger
private extension Logger {
static let hotkey = Logger(category: "Hotkey")
}
1 change: 0 additions & 1 deletion Ice/Hotkeys/HotkeyRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import Carbon.HIToolbox
import Cocoa
import Combine
import OSLog

/// An object that manages the registration, storage, and unregistration of hotkeys.
final class HotkeyRegistry {
Expand Down
10 changes: 2 additions & 8 deletions Ice/Hotkeys/KeyCombination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Carbon.HIToolbox
import Cocoa
import OSLog

struct KeyCombination: Hashable {
let key: KeyCode
Expand All @@ -32,11 +31,11 @@ private func getSystemReservedKeyCombinations() -> [KeyCombination] {
let status = CopySymbolicHotKeys(&symbolicHotkeys)

guard status == noErr else {
logError(to: .keyCombination, "CopySymbolicHotKeys returned invalid status: \(status)")
logError("CopySymbolicHotKeys returned invalid status: \(status)")
return []
}
guard let reservedHotkeys = symbolicHotkeys?.takeRetainedValue() as? [[String: Any]] else {
logError(to: .keyCombination, "Failed to serialize symbolic hotkeys")
logError("Failed to serialize symbolic hotkeys")
return []
}

Expand Down Expand Up @@ -84,8 +83,3 @@ extension KeyCombination: Codable {
try container.encode(modifiers.rawValue)
}
}

// MARK: - Logger
private extension Logger {
static let keyCombination = Logger(category: "KeyCombination")
}
1 change: 0 additions & 1 deletion Ice/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Ice
//

import OSLog
import SwiftUI

@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/Main/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Combine
import OSLog
import SwiftUI

/// The model for app-wide state.
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/Appearance/MenuBarAppearanceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// A manager for the appearance of the menu bar.
@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/Appearance/MenuBarOverlayPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

// MARK: - Overlay Panel

Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/MenuBarItemImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// Cache for menu bar item images.
final class MenuBarItemImageCache: ObservableObject {
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/MenuBarItemManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// Manager for menu bar items.
@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/MenuBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import AXSwift
import Combine
import OSLog
import SwiftUI

/// Manager for the state of the menu bar.
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/MenuBarSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Cocoa
import OSLog

/// A representation of a section in a menu bar.
@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/MenuBar/Spacing/MenuBarItemSpacingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// Manager for menu bar item spacing.
@MainActor
Expand Down
1 change: 0 additions & 1 deletion Ice/Settings/SettingsManagers/GeneralSettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Combine
import Foundation
import OSLog

@MainActor
final class GeneralSettingsManager: ObservableObject {
Expand Down
2 changes: 1 addition & 1 deletion Ice/Settings/SettingsManagers/HotkeySettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

import Combine
import OSLog
import Foundation

@MainActor
final class HotkeySettingsManager: ObservableObject {
Expand Down
8 changes: 1 addition & 7 deletions Ice/UI/IceUI/IceMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import SwiftUI
import OSLog

struct IceMenu<Title: View, Label: View, Content: View>: View {
@State private var isHovering = false
Expand Down Expand Up @@ -110,7 +109,7 @@ private struct IceMenuLayout<Title: View>: _VariadicView_UnaryViewRoot {

private final class IceMenuItemAction: Hashable {
static let nullAction = IceMenuItemAction {
logWarning(to: .iceMenu, "No action assigned to menu item")
logWarning("No action assigned to menu item")
}

let body: () -> Void
Expand Down Expand Up @@ -161,8 +160,3 @@ extension View {
preference(key: IceMenuItemActionKey.self, value: IceMenuItemAction(body: action))
}
}

// MARK: - Logger
private extension Logger {
static let iceMenu = Logger(category: "IceMenu")
}
1 change: 0 additions & 1 deletion Ice/UI/LayoutBar/LayoutBarPaddingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import Cocoa
import Combine
import OSLog

/// A Cocoa view that manages the menu bar layout interface.
final class LayoutBarPaddingView: NSView {
Expand Down
1 change: 0 additions & 1 deletion Ice/Utilities/EventMonitors/EventTap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Cocoa
import OSLog

/// A type that receives system events from various locations within the
/// event stream.
Expand Down
40 changes: 24 additions & 16 deletions Ice/Utilities/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,42 @@

import OSLog

/// A type that encapsulates logging behavior for Ice.
struct Logger {
fileprivate let base: os.Logger

/// Creates a logger for Ice using the specified category.
init(category: String) {
self.base = os.Logger(subsystem: Constants.bundleIdentifier, category: category)
}
}

extension Logger {
/// The default logger.
static let `default` = Logger(category: "Default")
}

/// Logs the given message using the specified logger and level.
func logMessage(to logger: Logger, at level: OSLogType, _ message: String) {
logger.log(level: level, "\(message, privacy: .public)")
func logMessage(to logger: Logger = .default, level: OSLogType, _ message: String) {
logger.base.log(level: level, "\(message, privacy: .public)")
}

/// Logs the given informative message using the specified logger.
func logInfo(to logger: Logger, _ message: String) {
logMessage(to: logger, at: .info, message)
func logInfo(to logger: Logger = .default, _ message: String) {
logMessage(to: logger, level: .info, message)
}

/// Logs the given debug message using the specified logger.
func logDebug(to logger: Logger, _ message: String) {
logMessage(to: logger, at: .debug, message)
func logDebug(to logger: Logger = .default, _ message: String) {
logMessage(to: logger, level: .debug, message)
}

/// Logs the given error message using the specified logger.
func logError(to logger: Logger, _ message: String) {
logMessage(to: logger, at: .error, message)
func logError(to logger: Logger = .default, _ message: String) {
logMessage(to: logger, level: .error, message)
}

/// Logs the given warning message using the specified logger.
func logWarning(to logger: Logger, _ message: String) {
func logWarning(to logger: Logger = .default, _ message: String) {
logError(to: logger, message)
}

extension Logger {
/// Creates a logger for Ice using the specified category.
init(category: String) {
self.init(subsystem: Constants.bundleIdentifier, category: category)
}
}
1 change: 0 additions & 1 deletion Ice/Utilities/MigrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

import Cocoa
import OSLog

@MainActor
struct MigrationManager {
Expand Down
12 changes: 3 additions & 9 deletions Ice/Utilities/MouseCursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
//

import CoreGraphics
import OSLog

/// A namespace for mouse cursor operations.
enum MouseCursor {
/// Hides the mouse cursor and increments the hide cursor count.
static func hide() {
let result = CGDisplayHideCursor(CGMainDisplayID())
if result != .success {
logError(to: .mouseCursor, "CGDisplayHideCursor failed with error \(result.logString)")
logError("CGDisplayHideCursor failed with error \(result.logString)")
}
}

/// Decrements the hide cursor count and shows the mouse cursor if the count is `0`.
static func show() {
let result = CGDisplayShowCursor(CGMainDisplayID())
if result != .success {
logError(to: .mouseCursor, "CGDisplayShowCursor failed with error \(result.logString)")
logError("CGDisplayShowCursor failed with error \(result.logString)")
}
}

Expand All @@ -30,7 +29,7 @@ enum MouseCursor {
static func warp(to point: CGPoint) {
let result = CGWarpMouseCursorPosition(point)
if result != .success {
logError(to: .mouseCursor, "CGWarpMouseCursorPosition failed with error \(result.logString)")
logError("CGWarpMouseCursorPosition failed with error \(result.logString)")
}
}

Expand All @@ -52,8 +51,3 @@ enum MouseCursor {
}
}
}

// MARK: - Logger
private extension Logger {
static let mouseCursor = Logger(category: "MouseCursor")
}

0 comments on commit bc31c26

Please sign in to comment.