Skip to content

Commit 7d2e74d

Browse files
committed
✨ Introduce Scribe Logging package
1 parent 7e82a85 commit 7d2e74d

48 files changed

Lines changed: 321 additions & 278 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Loop.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
2A28B6292EE5050C00A1E26B /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = 2A28B6282EE5050C00A1E26B /* Defaults */; };
1111
2A28B62C2EE5057C00A1E26B /* Luminare in Frameworks */ = {isa = PBXBuildFile; productRef = 2A28B62B2EE5057C00A1E26B /* Luminare */; };
12+
3EFD33252EE6DFA4007D9601 /* Scribe in Frameworks */ = {isa = PBXBuildFile; productRef = 3EFD33242EE6DFA4007D9601 /* Scribe */; };
1213
A883642F298B7288005D6C19 /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A883642E298B7288005D6C19 /* ServiceManagement.framework */; };
1314
F06D768A2DFF7A77007EEDA9 /* SkyLight.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F06D76892DFF7A77007EEDA9 /* SkyLight.framework */; };
1415
/* End PBXBuildFile section */
@@ -44,6 +45,7 @@
4445
isa = PBXFrameworksBuildPhase;
4546
buildActionMask = 2147483647;
4647
files = (
48+
3EFD33252EE6DFA4007D9601 /* Scribe in Frameworks */,
4749
2A28B6292EE5050C00A1E26B /* Defaults in Frameworks */,
4850
2A28B62C2EE5057C00A1E26B /* Luminare in Frameworks */,
4951
F06D768A2DFF7A77007EEDA9 /* SkyLight.framework in Frameworks */,
@@ -108,6 +110,7 @@
108110
packageProductDependencies = (
109111
2A28B6282EE5050C00A1E26B /* Defaults */,
110112
2A28B62B2EE5057C00A1E26B /* Luminare */,
113+
3EFD33242EE6DFA4007D9601 /* Scribe */,
111114
);
112115
productName = WindowManager;
113116
productReference = A8E59C35297F5E9A0064D4BA /* Loop.app */;
@@ -151,6 +154,7 @@
151154
packageReferences = (
152155
2A28B6272EE5050C00A1E26B /* XCRemoteSwiftPackageReference "Defaults" */,
153156
2A28B62A2EE5057C00A1E26B /* XCRemoteSwiftPackageReference "luminare" */,
157+
3EFD33232EE6DFA4007D9601 /* XCRemoteSwiftPackageReference "Scribe" */,
154158
);
155159
productRefGroup = A8E59C36297F5E9A0064D4BA /* Products */;
156160
projectDirPath = "";
@@ -449,6 +453,14 @@
449453
minimumVersion = 0.2.0;
450454
};
451455
};
456+
3EFD33232EE6DFA4007D9601 /* XCRemoteSwiftPackageReference "Scribe" */ = {
457+
isa = XCRemoteSwiftPackageReference;
458+
repositoryURL = "https://github.com/SenpaiHunters/Scribe";
459+
requirement = {
460+
branch = main;
461+
kind = branch;
462+
};
463+
};
452464
/* End XCRemoteSwiftPackageReference section */
453465

454466
/* Begin XCSwiftPackageProductDependency section */
@@ -462,6 +474,11 @@
462474
package = 2A28B62A2EE5057C00A1E26B /* XCRemoteSwiftPackageReference "luminare" */;
463475
productName = Luminare;
464476
};
477+
3EFD33242EE6DFA4007D9601 /* Scribe */ = {
478+
isa = XCSwiftPackageProductDependency;
479+
package = 3EFD33232EE6DFA4007D9601 /* XCRemoteSwiftPackageReference "Scribe" */;
480+
productName = Scribe;
481+
};
465482
/* End XCSwiftPackageProductDependency section */
466483
};
467484
rootObject = A8E59C2D297F5E9A0064D4BA /* Project object */;

Loop/Accent Color/AccentColorController.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
import Defaults
9-
import OSLog
9+
import Scribe
1010
import SwiftUI
1111

1212
/// In charge of processing and storing an up-to-date version of the user's accent color(s), according to their settings.
@@ -20,7 +20,6 @@ final class AccentColorController: ObservableObject {
2020

2121
private let wallpaperProcessor = WallpaperProcessor()
2222
private var observationTask: Task<(), Never>?
23-
private let logger = Logger(category: "AccentColorController")
2423

2524
private init() {
2625
self.observationTask = Task { [weak self] in
@@ -50,16 +49,16 @@ final class AccentColorController: ObservableObject {
5049
func refresh() async {
5150
switch Defaults[.accentColorMode] {
5251
case .system:
53-
logger.log("AccentColorController: Refreshing accent color based on system")
52+
Log.info("Refreshing accent color based on system accent setting", category: .accentColorController)
5453
color1 = Color.accentColor
5554
color2 = Defaults[.useGradient] ? Color(nsColor: NSColor.controlAccentColor.blended(withFraction: 0.5, of: .black)!) : Color.accentColor
5655
case .wallpaper:
57-
logger.log("AccentColorController: Refreshing accent color based on wallpaper")
56+
Log.info("Refreshing accent color based on wallpaper analysis", category: .accentColorController)
5857
let colors = await wallpaperProcessor.fetchLatest()
5958
color1 = colors.primary
6059
color2 = Defaults[.useGradient] ? colors.secondary : colors.primary
6160
case .custom:
62-
logger.log("AccentColorController: Refreshing accent color based on custom colors")
61+
Log.info("Refreshing accent color based on custom selection", category: .accentColorController)
6362
color1 = Defaults[.customAccentColor]
6463
color2 = Defaults[.useGradient] ? Defaults[.gradientColor] : Defaults[.customAccentColor]
6564
}

Loop/Accent Color/WallpaperProcessor.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import AppKit
99
import Defaults
10-
import OSLog
10+
import Scribe
1111
import SwiftUI
1212

1313
// MARK: - Wallpaper processor errors
@@ -47,7 +47,6 @@ public enum WallpaperProcessorError: LocalizedError {
4747
final class WallpaperProcessor {
4848
private var lastProcessedDate: Date = .distantPast
4949
private var lastResult: (primary: Color, secondary: Color) = (.black, .black)
50-
private let logger = Logger(category: "WallpaperProcessor")
5150

5251
/// Fetches the latest wallpaper colors, respecting a throttle period.
5352
/// This helps prevent excessive processing if called frequently, when the wallpaper is most likely unchanged.
@@ -97,12 +96,12 @@ final class WallpaperProcessor {
9796
// Use the second dominant color if possible, otherwise return the primary color.
9897
let secondaryColor = colors.count > 1 ? Color(colors[1]) : primaryColor
9998

100-
logger.info("Successfully calculated dominant colors from wallpaper")
99+
Log.info("Successfully calculated dominant colors from wallpaper", category: .wallpaperProcessor)
101100

102101
return (primaryColor, secondaryColor)
103102
} catch {
104103
// If an error occurs, print the error description.
105-
logger.error("Failed to fetch wallpaper colors: \(error.localizedDescription)")
104+
Log.error("Failed to fetch wallpaper colors: \(error.localizedDescription)", category: .wallpaperProcessor)
106105
return nil
107106
}
108107
}
@@ -175,7 +174,7 @@ extension NSImage {
175174
let dataProvider = resizedCGImage.dataProvider,
176175
let data = CFDataGetBytePtr(dataProvider.data)
177176
else {
178-
NSLog("Error: \(WallpaperProcessorError.imageResizeFailed)")
177+
Log.error("Error: \(WallpaperProcessorError.imageResizeFailed)", category: .wallpaperProcessor)
179178
return nil
180179
}
181180

@@ -298,7 +297,7 @@ extension NSImage {
298297
samplesPerPixel: 4, hasAlpha: true, isPlanar: false,
299298
colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0
300299
) else {
301-
NSLog("Error: \(WallpaperProcessorError.bitmapCreationFailed)")
300+
Log.error("Error: \(WallpaperProcessorError.bitmapCreationFailed)", category: .wallpaperProcessor)
302301
return nil
303302
}
304303
bitmapRep.size = newSize

Loop/App/AppDelegate+UNNotifications.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Kai Azim on 2024-06-03.
66
//
77

8+
import Scribe
89
import SwiftUI
910
import UserNotifications
1011

@@ -36,11 +37,11 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
3637
options: [.alert]
3738
) { accepted, error in
3839
if !accepted {
39-
Self.logger.warning("Notification access denied.")
40+
Log.warn("Notification access denied.", category: .appDelegate)
4041
}
4142

4243
if let error {
43-
Self.logger.error("Failed to request notification authorization: \(error.localizedDescription)")
44+
Log.error("Failed to request notification authorization: \(error.localizedDescription)", category: .appDelegate)
4445
}
4546
}
4647
}

Loop/App/AppDelegate.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
//
77

88
import Defaults
9-
import OSLog
9+
import Scribe
1010
import SwiftUI
1111
import UserNotifications
1212

1313
final class AppDelegate: NSObject, NSApplicationDelegate {
1414
private let urlCommandHandler = URLCommandHandler()
15-
static let logger = Logger(category: "AppDelegate")
1615

1716
private var launchedAsLoginItem: Bool {
1817
guard let event = NSAppleEventManager.shared().currentAppleEvent else { return false }
@@ -22,6 +21,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
2221
}
2322

2423
func applicationDidFinishLaunching(_: Notification) {
24+
configureLogging()
25+
2526
Task {
2627
await Defaults.iCloud.waitForSyncCompletion()
2728
}
@@ -63,13 +64,18 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
6364
)
6465
}
6566

67+
/// Applies baseline logging configuration for Scribe.
68+
private func configureLogging() {
69+
LogManager.shared.minimumLevel = .info
70+
}
71+
6672
@objc func handleGetURLEvent(_ event: NSAppleEventDescriptor, withReplyEvent _: NSAppleEventDescriptor) {
6773
guard let urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue,
6874
let url = URL(string: urlString) else {
69-
Self.logger.info("Failed to get URL from event")
75+
Log.info("Failed to get URL from event", category: .appDelegate)
7076
return
7177
}
72-
Self.logger.info("Received URL: \(url)")
78+
Log.info("Received URL: \(url)", category: .appDelegate)
7379
urlCommandHandler.handle(url)
7480
}
7581

Loop/App/DataPatcher.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@
77

88
import Defaults
99
import Foundation
10-
import OSLog
10+
import Scribe
1111

1212
enum DataPatcher {
13-
private static let logger = Logger(category: "DataPatcher")
14-
1513
static func run() {
1614
let initialPatches = Defaults[.patchesApplied]
1715

1816
if !initialPatches.contains(.accentColorMode) {
1917
// Migrate to accent color mode
2018
// We need to migrate `useSystemAccentColor` and `processWallpaper` over to `accentColorMode`
21-
if Defaults[.useSystemAccentColor] {
19+
let useSystemAccentColor: Bool = Defaults[.useSystemAccentColor]
20+
let processWallpaper: Bool = Defaults[.processWallpaper]
21+
22+
if useSystemAccentColor {
2223
Defaults[.accentColorMode] = .system
23-
} else if Defaults[.processWallpaper] {
24+
} else if processWallpaper {
2425
Defaults[.accentColorMode] = .wallpaper
2526
} else {
2627
Defaults[.accentColorMode] = .custom
2728
}
2829

2930
Defaults[.patchesApplied].formUnion(.accentColorMode)
30-
logger.info("DataPatcher: Ran patch accentColorMode")
31+
Log.info("Ran patch accentColorMode", category: .dataPatcher)
3132
}
3233
}
3334

Loop/Core/LoopManager.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
import Defaults
9-
import OSLog
9+
import Scribe
1010
import SwiftUI
1111

1212
// MARK: - LoopManager
@@ -15,8 +15,6 @@ final class LoopManager: ObservableObject {
1515
static let shared = LoopManager()
1616
private init() {}
1717

18-
private let logger = Logger(category: "LoopManager")
19-
2018
// Size Adjustment
2119
static var sidesToAdjust: Edge.Set?
2220
static var lastTargetFrame: CGRect = .zero
@@ -113,7 +111,7 @@ extension LoopManager {
113111
return
114112
}
115113

116-
logger.info("Opening Loop with starting action: \(startingAction?.description ?? "(none)") and target window: \(window?.description ?? "(none)")")
114+
Log.info("Opening Loop with starting action: \(startingAction?.description ?? "(none)") and target window: \(window?.description ?? "(none)")", category: .loopManager)
117115

118116
// Record the first frame in advance if the preview window is disabled
119117
if let window,
@@ -162,7 +160,7 @@ extension LoopManager {
162160

163161
private func closeLoop(forceClose: Bool) {
164162
guard isLoopActive == true else { return }
165-
logger.info("Closing Loop (force closed: \(forceClose))")
163+
Log.info("Closing Loop (force closed: \(forceClose))", category: .loopManager)
166164

167165
closeWindows()
168166
isLoopActive = false
@@ -383,7 +381,7 @@ extension LoopManager {
383381
}
384382
}
385383

386-
logger.info("Screen changed: \(newScreen.localizedName)")
384+
Log.info("Screen changed: \(newScreen.localizedName)", category: .loopManager)
387385

388386
return
389387
}
@@ -416,7 +414,7 @@ extension LoopManager {
416414
// This can work even without a current window (navigates from screen center)
417415
if newAction.direction.willFocusWindow {
418416
guard let focusEdge = newAction.direction.focusEdge else {
419-
logger.error("willFocusWindow is true but focusEdge is nil for \(newAction.direction.debugDescription)")
417+
Log.error("willFocusWindow is true but focusEdge is nil for \(newAction.direction.debugDescription)", category: .loopManager)
420418
return
421419
}
422420

@@ -432,7 +430,7 @@ extension LoopManager {
432430
}
433431
}
434432

435-
logger.info("Window action changed: \(newAction.description)")
433+
Log.info("Window action changed: \(newAction.description)", category: .loopManager)
436434
}
437435
}
438436

Loop/Core/Observers/MouseInteractionObserver.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
//
77

88
import Defaults
9-
import OSLog
9+
import Scribe
1010
import SwiftUI
1111

1212
final class MouseInteractionObserver {
13-
private let logger = Logger(category: "MouseInteractionObserver")
14-
1513
// Parameters
1614
private let windowActionCache: WindowActionCache
1715
private let changeAction: (WindowAction) -> ()
@@ -55,7 +53,7 @@ final class MouseInteractionObserver {
5553
)
5654

5755
// swiftformat:disable:next redundantSelf
58-
logger.info("Started with initial mouse position: \(self.getInitialMousePosition().debugDescription)")
56+
Log.info("Started with initial mouse position: \(self.getInitialMousePosition().debugDescription)", category: .mouseInteractionObserver)
5957
}
6058

6159
@MainActor
@@ -66,7 +64,7 @@ final class MouseInteractionObserver {
6664
previousAngleToMouse = .zero
6765
previousDistanceToMouse = .zero
6866

69-
logger.info("Stopped, all stored states cleared.")
67+
Log.info("Stopped, all stored states cleared.", category: .mouseInteractionObserver)
7068
}
7169

7270
private func mouseEvent(_ event: CGEvent) {

0 commit comments

Comments
 (0)