Skip to content

Commit

Permalink
Log window (#4109)
Browse files Browse the repository at this point in the history
* Add basic log window functions

* Fix constraints in log window

* Fix table view constraints

* Add predicates for LogArrayController

* Add window & delegate references

* Implement saving logs to file

* Add a menu item to show log window (cmd+L)

* Add copy to tableview menu

* Add copy action for App menu

* Refine log subsystem names for plugin instances

* Add log indicators

* Change shortcut to CMD+Shift+L; fix color order

* Fix log level icon disabled by default

* Update upon review

* Update upon review

- Rename Log Window to Log Viewer
- Save logs now saves all available logs instead of filtered logs

* Lower the mpv log level to debug

Add a map from mpv's log level to iina's log level

* Fix after rebasing

* Add a new section for logging settings

* Update upon review

- Fix duplicated subsystems could appear
- Fix binding issues
- Revert mpv log level to warn

* Fix various issues

- Add `:` after Subsystem the label
- Enlarge the maximum length of the last column
- Add AutosaveName to the window so that it remembers last open size
- Internalization

---------

Co-authored-by: Collider LI <lhc199652@gmail.com>
  • Loading branch information
uiryuu and lhc70000 committed Apr 4, 2023
1 parent 4f3fef2 commit d161baa
Show file tree
Hide file tree
Showing 49 changed files with 2,357 additions and 79 deletions.
72 changes: 72 additions & 0 deletions iina.xcodeproj/project.pbxproj
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
1326717E20852D0D000FA7E2 /* SubChooseViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1326718020852D0D000FA7E2 /* SubChooseViewController.xib */; };
34ACA04B29DBB0090030C09C /* LogWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 34ACA04D29DBB0090030C09C /* LogWindowController.xib */; };
34FD798E291C76A600963EDE /* LogWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34FD798D291C76A600963EDE /* LogWindowController.swift */; };
49542975216C34950058F680 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49542974216C34950058F680 /* Cocoa.framework */; };
49542978216C34950058F680 /* SafariExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49542977216C34950058F680 /* SafariExtensionHandler.swift */; };
49542980216C34950058F680 /* open-in-iina.js in Resources */ = {isa = PBXBuildFile; fileRef = 4954297F216C34950058F680 /* open-in-iina.js */; };
Expand Down Expand Up @@ -738,6 +740,36 @@
348BFFFD28DC688D0045F683 /* sr-Latn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "sr-Latn"; path = "sr-Latn.lproj/OpenURLWindowController.strings"; sourceTree = "<group>"; };
348BFFFE28DC688D0045F683 /* sr-Latn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "sr-Latn"; path = "sr-Latn.lproj/HistoryWindowController.strings"; sourceTree = "<group>"; };
348BFFFF28DC688D0045F683 /* sr-Latn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "sr-Latn"; path = "sr-Latn.lproj/InitialWindowController.strings"; sourceTree = "<group>"; };
34ACA04C29DBB0090030C09C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LogWindowController.xib; sourceTree = "<group>"; };
34ACA04F29DBB0180030C09C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05129DBB0190030C09C /* af */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = af; path = af.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05329DBB01A0030C09C /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05529DBB01B0030C09C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LogWindowController.strings"; sourceTree = "<group>"; };
34ACA05729DBB01B0030C09C /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/LogWindowController.strings"; sourceTree = "<group>"; };
34ACA05929DBB01C0030C09C /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05B29DBB01C0030C09C /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05D29DBB01E0030C09C /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA05F29DBB01F0030C09C /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/LogWindowController.strings"; sourceTree = "<group>"; };
34ACA06129DBB01F0030C09C /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06329DBB01F0030C09C /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06529DBB0200030C09C /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06729DBB0200030C09C /* hi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hi; path = hi.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06929DBB0200030C09C /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06B29DBB0210030C09C /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06D29DBB0210030C09C /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA06F29DBB0210030C09C /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07129DBB0220030C09C /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07329DBB0220030C09C /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07529DBB0230030C09C /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/LogWindowController.strings"; sourceTree = "<group>"; };
34ACA07729DBB0230030C09C /* ro */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ro; path = ro.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07929DBB0230030C09C /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07B29DBB0230030C09C /* sr-Latn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "sr-Latn"; path = "sr-Latn.lproj/LogWindowController.strings"; sourceTree = "<group>"; };
34ACA07D29DBB0240030C09C /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA07F29DBB0240030C09C /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA08129DBB0250030C09C /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA08329DBB0260030C09C /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34ACA08529DBB0260030C09C /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/LogWindowController.strings; sourceTree = "<group>"; };
34FD798D291C76A600963EDE /* LogWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogWindowController.swift; sourceTree = "<group>"; };
440DDE351E9010420063E211 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/MainMenu.strings; sourceTree = "<group>"; };
440DDE361E9010420063E211 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/MainWindowController.strings; sourceTree = "<group>"; };
440DDE371E9010420063E211 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/QuickSettingViewController.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2070,6 +2102,8 @@
8F49C370213EFB7E0076C4F9 /* MiniPlayerWindowController.xib */,
E36E8D7A24F6052F00B8C097 /* GuideWindowController.swift */,
E34E909C24F821280073BF04 /* GuideWindowController.xib */,
34FD798D291C76A600963EDE /* LogWindowController.swift */,
34ACA04D29DBB0090030C09C /* LogWindowController.xib */,
84D0FB7B1F5E510C00C6A6A7 /* Interactive Mode */,
84D377691D74163B007F7396 /* Video */,
84D377681D7413D8007F7396 /* Accessories */,
Expand Down Expand Up @@ -2729,6 +2763,7 @@
84D0FB821F5E6A3800C6A6A7 /* FreeSelectingViewController.xib in Resources */,
8400D5E11E1AB32F006785F5 /* PrefUIViewController.xib in Resources */,
E338368A202651CF00ABC812 /* PrefOSCToolbarDraggingItemViewController.xib in Resources */,
34ACA04B29DBB0090030C09C /* LogWindowController.xib in Resources */,
8483FB001EDFF325000F55D6 /* Credits.rtf in Resources */,
E353070621496CE4008FE492 /* PrefPluginViewController.xib in Resources */,
84F5D49A1E44E9A50060A838 /* KeyBinding.strings in Resources */,
Expand Down Expand Up @@ -2934,6 +2969,7 @@
E395858A253314400096811F /* JavascriptAPISidebarView.swift in Sources */,
E33BA5C4204315740069A0F6 /* AssrtSubtitle.swift in Sources */,
E32693F924BA138000BF7ADC /* JavascriptPluginSubtitleItem.swift in Sources */,
34FD798E291C76A600963EDE /* LogWindowController.swift in Sources */,
844DE1BF1D3E2B9900272589 /* MPVEvent.swift in Sources */,
845040471E0B0F500079C194 /* CropSettingsViewController.swift in Sources */,
E33836852026223800ABC812 /* PrefOSCToolbarSettingsSheetController.swift in Sources */,
Expand Down Expand Up @@ -3032,6 +3068,42 @@
name = SubChooseViewController.xib;
sourceTree = "<group>";
};
34ACA04D29DBB0090030C09C /* LogWindowController.xib */ = {
isa = PBXVariantGroup;
children = (
34ACA04C29DBB0090030C09C /* Base */,
34ACA04F29DBB0180030C09C /* en */,
34ACA05129DBB0190030C09C /* af */,
34ACA05329DBB01A0030C09C /* ca */,
34ACA05529DBB01B0030C09C /* zh-Hans */,
34ACA05729DBB01B0030C09C /* zh-Hant */,
34ACA05929DBB01C0030C09C /* cs */,
34ACA05B29DBB01C0030C09C /* da */,
34ACA05D29DBB01E0030C09C /* nl */,
34ACA05F29DBB01F0030C09C /* en-GB */,
34ACA06129DBB01F0030C09C /* fi */,
34ACA06329DBB01F0030C09C /* fr */,
34ACA06529DBB0200030C09C /* de */,
34ACA06729DBB0200030C09C /* hi */,
34ACA06929DBB0200030C09C /* hu */,
34ACA06B29DBB0210030C09C /* it */,
34ACA06D29DBB0210030C09C /* ja */,
34ACA06F29DBB0210030C09C /* ko */,
34ACA07129DBB0220030C09C /* pl */,
34ACA07329DBB0220030C09C /* pt */,
34ACA07529DBB0230030C09C /* pt-BR */,
34ACA07729DBB0230030C09C /* ro */,
34ACA07929DBB0230030C09C /* ru */,
34ACA07B29DBB0230030C09C /* sr-Latn */,
34ACA07D29DBB0240030C09C /* sk */,
34ACA07F29DBB0240030C09C /* es */,
34ACA08129DBB0250030C09C /* sv */,
34ACA08329DBB0260030C09C /* uk */,
34ACA08529DBB0260030C09C /* tr */,
);
name = LogWindowController.xib;
sourceTree = "<group>";
};
8400D5C81E1AB2F1006785F5 /* MainWindowController.xib */ = {
isa = PBXVariantGroup;
children = (
Expand Down
45 changes: 40 additions & 5 deletions iina/AppDelegate.swift
Expand Up @@ -51,6 +51,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
lazy var inspector: InspectorWindowController = InspectorWindowController()
lazy var historyWindow: HistoryWindowController = HistoryWindowController()
lazy var guideWindow: GuideWindowController = GuideWindowController()
lazy var logWindow: LogWindowController = LogWindowController()

lazy var vfWindow: FilterWindowController = {
let w = FilterWindowController()
Expand Down Expand Up @@ -94,15 +95,23 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
isReady = true
}

// MARK: - SPUUpdaterDelegate
// MARK: - Logs
private let observedPrefKeys: [Preference.Key] = [.logLevel]

@IBOutlet weak var updaterController: SPUStandardUpdaterController!
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard let keyPath = keyPath, let change = change else { return }

func feedURLString(for updater: SPUUpdater) -> String? {
return Preference.bool(for: .receiveBetaUpdate) ? AppData.appcastBetaLink : AppData.appcastLink
switch keyPath {
case Preference.Key.logLevel.rawValue:
if let newValue = change[.newKey] as? Int {
Logger.Level.preferred = Logger.Level(rawValue: newValue.clamped(to: 0...3))!
}

default:
return
}
}

// MARK: - App Delegate

/// Log details about when and from what sources IINA was built.
///
Expand All @@ -120,10 +129,24 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
Logger.log("Built \(date) from branch \(branch), commit \(commit)")
}


// MARK: - SPUUpdaterDelegate
@IBOutlet weak var updaterController: SPUStandardUpdaterController!

func feedURLString(for updater: SPUUpdater) -> String? {
return Preference.bool(for: .receiveBetaUpdate) ? AppData.appcastBetaLink : AppData.appcastLink
}

// MARK: - App Delegate

func applicationWillFinishLaunching(_ notification: Notification) {
// Must setup preferences before logging so log level is set correctly.
registerUserDefaultValues()

observedPrefKeys.forEach { key in
UserDefaults.standard.addObserver(self, forKeyPath: key.rawValue, options: .new, context: nil)
}

// Start the log file by logging the version of IINA producing the log file.
let (version, build) = InfoDictionary.shared.version
Logger.log("IINA \(version) Build \(build)")
Expand Down Expand Up @@ -215,6 +238,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
commandLineStatus.filenames = iinaArgFilenames
}

deinit {
ObjcUtils.silenced {
for key in self.observedPrefKeys {
UserDefaults.standard.removeObserver(self, forKeyPath: key.rawValue)
}
}
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
Logger.log("App launched")

Expand Down Expand Up @@ -727,6 +758,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUUpdaterDelegate {
historyWindow.showWindow(self)
}

@IBAction func showLogWindow(_ sender: AnyObject) {
logWindow.showWindow(self)
}

@IBAction func showHighlights(_ sender: AnyObject) {
guideWindow.show(pages: [.highlights])
}
Expand Down
2 changes: 1 addition & 1 deletion iina/AssrtSubtitle.swift
Expand Up @@ -291,5 +291,5 @@ class Assrt {
}

extension Logger.Sub {
static let assrt = Logger.Subsystem(rawValue: "assrt")
static let assrt = Logger.makeSubsystem("assrt")
}
2 changes: 1 addition & 1 deletion iina/AutoFileMatcher.swift
Expand Up @@ -8,7 +8,7 @@

import Foundation

fileprivate let subsystem = Logger.Subsystem(rawValue: "fmatcher")
fileprivate let subsystem = Logger.makeSubsystem("fmatcher")

class AutoFileMatcher {

Expand Down

0 comments on commit d161baa

Please sign in to comment.