Logging functionality (#71)
Enhancing logging functionality, including log format options
This commit is contained in:
1 parent
bf012927b4
commit
a4e4b6027d
7 files changed
+238
-60
No files matched your search
@@ -21,25 +21,26 @@
|
||||
<string>windowSize</string>
|
||||
<string>rememberWindowSize</string>
|
||||
<string>chaptersPreviewTrack</string>
|
||||
<string>SBLogFormat</string>
|
||||
</declaredKeys>
|
||||
</userDefaultsController>
|
||||
<customView id="76">
|
||||
<rect key="frame" x="0.0" y="0.0" width="660" height="299"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="660" height="316"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<customView translatesAutoresizingMaskIntoConstraints="NO" id="dxI-5Q-gDD">
|
||||
<rect key="frame" x="136" y="0.0" width="389" height="299"/>
|
||||
<rect key="frame" x="133" y="0.0" width="395" height="316"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XPF-Mh-XYC">
|
||||
<rect key="frame" x="147" y="139" width="57" height="14"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XPF-Mh-XYC">
|
||||
<rect key="frame" x="147" y="150" width="57" height="14"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Beginning" id="3Vs-qA-7Z6">
|
||||
<font key="font" metaFont="message" size="11"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="249">
|
||||
<rect key="frame" x="129" y="95" width="165" height="14"/>
|
||||
<textField focusRingType="none" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="249">
|
||||
<rect key="frame" x="129" y="107" width="165" height="14"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="USA ratings are always shown." id="250">
|
||||
<font key="font" metaFont="message" size="11"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -47,7 +48,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="133">
|
||||
<rect key="frame" x="125" y="44" width="188" height="32"/>
|
||||
<rect key="frame" x="124" y="43" width="182" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Clear recent searches" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="134">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -57,7 +58,7 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="80">
|
||||
<rect key="frame" x="129" y="204" width="117" height="18"/>
|
||||
<rect key="frame" x="129" y="217" width="121" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Remember Size" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="86">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -70,8 +71,8 @@
|
||||
</binding>
|
||||
</connections>
|
||||
</button>
|
||||
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="139">
|
||||
<rect key="frame" x="18" y="54" width="107" height="16"/>
|
||||
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="139">
|
||||
<rect key="frame" x="18" y="53" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Privacy:" id="140">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -79,7 +80,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="82">
|
||||
<rect key="frame" x="129" y="180" width="232" height="18"/>
|
||||
|
||||
<buttonCell key="cell" type="check" title="Create Preview Images at position:" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="84">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -93,15 +94,15 @@
|
||||
</connections>
|
||||
</button>
|
||||
<slider verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="JhA-jk-CGt">
|
||||
<rect key="frame" x="147" y="152" width="214" height="24"/>
|
||||
<rect key="frame" x="147" y="158" width="220" height="28"/>
|
||||
<sliderCell key="cell" state="on" alignment="left" maxValue="1" doubleValue="0.5" tickMarkPosition="below" numberOfTickMarks="7" sliderType="linear" id="iKX-dX-4IV"/>
|
||||
<connections>
|
||||
<binding destination="3" name="value" keyPath="values.SBChaptersPreviewPosition" id="JtQ-lM-MNU"/>
|
||||
<binding destination="3" name="enabled" keyPath="values.chaptersPreviewTrack" id="hNU-uO-zsL"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<textField horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="206">
|
||||
<rect key="frame" x="18" y="115" width="107" height="16"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="206">
|
||||
<rect key="frame" x="18" y="126" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Show ratings for:" id="207">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -109,7 +110,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="136">
|
||||
<rect key="frame" x="125" y="13" width="188" height="32"/>
|
||||
<rect key="frame" x="124" y="13" width="182" height="32"/>
|
||||
<buttonCell key="cell" type="push" title="Delete cached metadata" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="137">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -118,8 +119,8 @@
|
||||
<action selector="deleteCachedMetadata:" target="-2" id="141"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="81">
|
||||
<rect key="frame" x="18" y="181" width="107" height="16"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="81">
|
||||
<rect key="frame" x="18" y="192" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Chapters:" id="85">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -127,7 +128,7 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="B5v-6Q-3Qa">
|
||||
<rect key="frame" x="129" y="242" width="242" height="18"/>
|
||||
<rect key="frame" x="129" y="257" width="246" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Automatically check for update daily" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="2Pf-pq-4IX">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -136,32 +137,48 @@
|
||||
<binding destination="3" name="value" keyPath="values.SUEnableAutomaticChecks" id="6AF-uh-wt7"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="77">
|
||||
<rect key="frame" x="18" y="263" width="107" height="16"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="77">
|
||||
<rect key="frame" x="18" y="280" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="At Launch:" id="89">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tVb-Qq-sU7">
|
||||
<rect key="frame" x="337" y="139" width="24" height="14"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tVb-Qq-sU7">
|
||||
<rect key="frame" x="343" y="150" width="24" height="14"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="End" id="He0-rl-DBi">
|
||||
<font key="font" metaFont="message" size="11"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="78">
|
||||
<rect key="frame" x="18" y="205" width="107" height="16"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="78">
|
||||
<rect key="frame" x="18" y="218" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Window:" id="88">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<popUpButton verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="logFormatPopup">
|
||||
<rect key="frame" x="128" y="75" width="187" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="logFormatCell">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="message"/>
|
||||
<menu key="menu" id="logFormatMenu"/>
|
||||
</popUpButtonCell>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="180" id="logFormatWidth"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<accessibilityConnection property="title" destination="logFormatLabel" id="logFormatAccessibility"/>
|
||||
<binding destination="-2" name="content" keyPath="logFormatOptions" id="logFormatContentBinding"/>
|
||||
<binding destination="3" name="selectedTag" keyPath="values.SBLogFormat" previousBinding="logFormatContentBinding" id="logFormatBinding"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="79">
|
||||
<rect key="frame" x="129" y="262" width="126" height="18"/>
|
||||
<rect key="frame" x="129" y="279" width="130" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Show open panel" bezelStyle="regularSquare" imagePosition="left" alignment="left" state="on" inset="2" id="87">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -171,15 +188,15 @@
|
||||
</connections>
|
||||
</button>
|
||||
<popUpButton verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="236">
|
||||
<rect key="frame" x="129" y="108" width="185" height="25"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="180" id="mhj-Zx-MME"/>
|
||||
</constraints>
|
||||
<rect key="frame" x="128" y="119" width="187" height="25"/>
|
||||
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="237">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<menu key="menu" id="238"/>
|
||||
</popUpButtonCell>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="180" id="mhj-Zx-MME"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<accessibilityConnection property="title" destination="206" id="SzO-00-e3U"/>
|
||||
<action selector="updateRatingsCountry:" target="-2" id="242"/>
|
||||
@@ -187,14 +204,22 @@
|
||||
<binding destination="123" name="selectedValue" keyPath="values.SBRatingsCountry" previousBinding="245" id="248"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mNP-6I-gV4">
|
||||
<rect key="frame" x="232" y="139" width="44" height="14"/>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mNP-6I-gV4">
|
||||
<rect key="frame" x="235" y="150" width="44" height="14"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Middle" id="2o1-dB-mt1">
|
||||
<font key="font" metaFont="message" size="11"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="logFormatLabel">
|
||||
<rect key="frame" x="18" y="82" width="107" height="16"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Log Format:" id="logFormatLabelCell">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="236" secondAttribute="trailing" constant="20" symbolic="YES" id="1oW-ke-hqe"/>
|
||||
@@ -212,7 +237,7 @@
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="79" secondAttribute="trailing" constant="20" symbolic="YES" id="C2B-fq-5vM"/>
|
||||
<constraint firstItem="81" firstAttribute="leading" secondItem="78" secondAttribute="leading" id="Ctg-6r-Vpm"/>
|
||||
<constraint firstAttribute="bottom" secondItem="136" secondAttribute="bottom" constant="20" symbolic="YES" id="Cxf-3a-EqU"/>
|
||||
<constraint firstItem="133" firstAttribute="top" secondItem="249" secondAttribute="bottom" constant="23" id="DFU-xm-8vq"/>
|
||||
<constraint firstItem="133" firstAttribute="top" secondItem="249" secondAttribute="bottom" constant="37" id="DFU-xm-8vq"/>
|
||||
<constraint firstItem="B5v-6Q-3Qa" firstAttribute="leading" secondItem="79" secondAttribute="leading" id="FJg-U6-HDs"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="B5v-6Q-3Qa" secondAttribute="trailing" constant="20" id="J3X-XR-5sZ"/>
|
||||
<constraint firstItem="82" firstAttribute="leading" secondItem="81" secondAttribute="trailing" constant="8" id="LHd-r8-b8o"/>
|
||||
@@ -241,6 +266,12 @@
|
||||
<constraint firstItem="mNP-6I-gV4" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="XPF-Mh-XYC" secondAttribute="trailing" constant="8" symbolic="YES" id="jyx-OY-6tw"/>
|
||||
<constraint firstItem="133" firstAttribute="firstBaseline" secondItem="139" secondAttribute="firstBaseline" id="kA6-a1-Krp"/>
|
||||
<constraint firstItem="249" firstAttribute="leading" secondItem="236" secondAttribute="leading" id="kh1-gL-cmS"/>
|
||||
<constraint firstItem="logFormatPopup" firstAttribute="firstBaseline" secondItem="logFormatLabel" secondAttribute="firstBaseline" id="logFormatBaseline"/>
|
||||
<constraint firstItem="logFormatLabel" firstAttribute="leading" secondItem="78" secondAttribute="leading" id="logFormatLabelLeading"/>
|
||||
<constraint firstItem="logFormatLabel" firstAttribute="width" secondItem="78" secondAttribute="width" id="logFormatLabelWidth"/>
|
||||
<constraint firstItem="logFormatPopup" firstAttribute="leading" secondItem="logFormatLabel" secondAttribute="trailing" constant="8" id="logFormatLeading"/>
|
||||
<constraint firstItem="logFormatLabel" firstAttribute="top" secondItem="80" secondAttribute="bottom" constant="120" id="logFormatTop"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="logFormatPopup" secondAttribute="trailing" constant="20" symbolic="YES" id="logFormatTrailing"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="249" secondAttribute="trailing" constant="20" symbolic="YES" id="mef-Mj-rvp"/>
|
||||
<constraint firstItem="236" firstAttribute="leading" secondItem="206" secondAttribute="trailing" constant="8" id="n47-AS-gXR"/>
|
||||
<constraint firstItem="80" firstAttribute="leading" secondItem="78" secondAttribute="trailing" constant="8" id="nPD-Zb-eKT"/>
|
||||
|
||||
@@ -66,34 +66,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
@IBOutlet weak var sendToExternalApp: NSMenuItem!
|
||||
|
||||
private static func appSupportURL() -> URL {
|
||||
let fileManager = FileManager.default
|
||||
if let url = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask)
|
||||
.first?.appendingPathComponent("Subler") {
|
||||
|
||||
do {
|
||||
if fileManager.fileExists(atPath: url.path) == false {
|
||||
try fileManager.createDirectory(at: url, withIntermediateDirectories: true, attributes: [:])
|
||||
}
|
||||
}
|
||||
catch _ {
|
||||
fatalError("Couldn't create the app support directory")
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
else {
|
||||
fatalError("Couldn't find the app support directory")
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor private lazy var prefsController: PrefsWindowController = {
|
||||
return PrefsWindowController()
|
||||
}()
|
||||
|
||||
private lazy var logger: Logger = {
|
||||
return Logger(fileURL: AppDelegate.appSupportURL().appendingPathComponent("debugLog.txt"))
|
||||
}()
|
||||
private let logger = Logger.makeDefault()
|
||||
|
||||
@MainActor private lazy var activityWindowController: ActivityWindowController = {
|
||||
return ActivityWindowController(logger: logger)
|
||||
@@ -199,6 +176,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
//if Prefs.suppressDonationAlert == false {
|
||||
// runDonateAlert()
|
||||
//}
|
||||
_ = logger // force lazy init
|
||||
}
|
||||
|
||||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
||||
|
||||
@@ -329,6 +329,8 @@ final class FileImportController: ViewController, NSTableViewDataSource, NSTable
|
||||
}
|
||||
|
||||
@IBAction func addTracks(_ sender: Any) {
|
||||
logTracksTable()
|
||||
|
||||
var selectedTracks: [MP42Track] = []
|
||||
|
||||
for trackSettings in settings where trackSettings.checked {
|
||||
@@ -521,4 +523,93 @@ final class FileImportController: ViewController, NSTableViewDataSource, NSTable
|
||||
return 18
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private methods
|
||||
|
||||
private func logTracksTable() {
|
||||
let logger = Logger.makeDefault()
|
||||
|
||||
// Helper function to truncate strings
|
||||
func truncate(_ str: String, to length: Int) -> String {
|
||||
if str.count <= length {
|
||||
return str.padding(toLength: length, withPad: " ", startingAt: 0)
|
||||
}
|
||||
return String(str.prefix(length - 1)) + "~"
|
||||
}
|
||||
|
||||
// Helper function to format duration
|
||||
func formatDuration(_ duration: Double, timescale: UInt32) -> String {
|
||||
if duration <= 0 || timescale == 0 {
|
||||
return "Unknown"
|
||||
}
|
||||
let seconds = duration / Double(timescale)
|
||||
let hours = Int(seconds) / 3600
|
||||
let minutes = (Int(seconds) % 3600) / 60
|
||||
let secs = Int(seconds) % 60
|
||||
let millisecs = Int((seconds - Double(Int(seconds))) * 1000)
|
||||
return String(format: "%02d:%02d:%02d.%03d", hours, minutes, secs, millisecs)
|
||||
}
|
||||
|
||||
// Build the entire table as a single string
|
||||
var tableLines: [String] = []
|
||||
|
||||
tableLines.append("File Import: Processing tracks with applied settings:")
|
||||
tableLines.append("----------------------------------------------------------------------------------------------")
|
||||
tableLines.append("| | Id | Name | Duration | Language | Info | Action |")
|
||||
tableLines.append("----------------------------------------------------------------------------------------------")
|
||||
|
||||
var trackId = 1
|
||||
for item in items {
|
||||
switch item {
|
||||
case .file(_):
|
||||
// Skip file headers in table format
|
||||
break
|
||||
|
||||
case .track(let settings):
|
||||
let track = settings.track
|
||||
let info: String
|
||||
|
||||
switch track {
|
||||
case is MP42VideoTrack:
|
||||
info = "\(track.format)"
|
||||
case is MP42AudioTrack:
|
||||
let audioTrack = track as! MP42AudioTrack
|
||||
info = "\(track.format) (\(audioTrack.channels)ch)"
|
||||
case is MP42SubtitleTrack:
|
||||
info = "\(track.format)"
|
||||
case is MP42ChapterTrack:
|
||||
info = "Chapter track"
|
||||
default:
|
||||
info = "\(track.format)"
|
||||
}
|
||||
|
||||
// Get the selected action description
|
||||
let selectedAction = settings.actions.first { $0.tag == settings.selectedActionTag }
|
||||
let action = selectedAction?.title ?? "Unknown"
|
||||
|
||||
// Format the data with proper truncation and alignment
|
||||
let name = truncate(track.name.isEmpty ? "Unnamed" : track.name, to: 21)
|
||||
let language = truncate(MP42Languages.defaultManager.localizedLang(forExtendedTag: track.language), to: 13)
|
||||
let infoTruncated = truncate(track.formatSummary, to: 10)
|
||||
let actionTruncated = truncate(action, to: 13)
|
||||
let duration = formatDuration(Double(track.duration), timescale: track.timescale)
|
||||
let selected = settings.checked ? "X" : " "
|
||||
let id = String(format: "%02d", trackId)
|
||||
|
||||
// Create properly aligned row with fixed column widths
|
||||
// The truncate function now handles padding, so we just need to pad duration
|
||||
let durationPadded = duration.padding(toLength: 12, withPad: " ", startingAt: 0)
|
||||
|
||||
let row = "| \(selected) | \(id) | \(name) | \(durationPadded) | \(language) | \(infoTruncated) | \(actionTruncated) |"
|
||||
tableLines.append(row)
|
||||
|
||||
trackId += 1
|
||||
}
|
||||
}
|
||||
|
||||
tableLines.append("----------------------------------------------------------------------------------------------")
|
||||
|
||||
// Log the entire table as a single entry
|
||||
logger.write(toLog: tableLines.joined(separator: "\n"))
|
||||
}
|
||||
}
|
||||
@@ -37,4 +37,11 @@ class GeneralPrefsViewController: NSViewController {
|
||||
|
||||
@objc dynamic var ratingsCountries: [String] { return Ratings.shared.countries.map { $0.displayName } }
|
||||
|
||||
@objc dynamic var logFormatOptions: [String] {
|
||||
return [
|
||||
"Time Only",
|
||||
"Date and Time"
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
+65
-3
@@ -8,6 +8,11 @@
|
||||
import Foundation
|
||||
import MP42Foundation
|
||||
|
||||
enum LogFormat: Int {
|
||||
case timeOnly = 0
|
||||
case dateAndTime = 1
|
||||
}
|
||||
|
||||
final class Logger : NSObject, MP42Logging {
|
||||
|
||||
var delegate: MP42Logging?
|
||||
@@ -15,7 +20,14 @@ final class Logger : NSObject, MP42Logging {
|
||||
private let fileURL: URL
|
||||
private let queue: DispatchQueue
|
||||
|
||||
init(fileURL: URL) {
|
||||
private var format: LogFormat {
|
||||
get {
|
||||
let logPref: Int = Prefs.logFormat
|
||||
return LogFormat(rawValue: logPref) ?? .timeOnly
|
||||
}
|
||||
}
|
||||
|
||||
init(fileURL: URL, format: LogFormat = Logger.defaultFormat()) {
|
||||
self.fileURL = fileURL
|
||||
self.queue = DispatchQueue(label: "org.subler.LogQueue")
|
||||
}
|
||||
@@ -24,7 +36,17 @@ final class Logger : NSObject, MP42Logging {
|
||||
var currentTime = time(nil)
|
||||
if let localTime = localtime(¤tTime) {
|
||||
let p = localTime.pointee
|
||||
return "\(p.tm_hour):\(p.tm_min):\(p.tm_sec)"
|
||||
return String(format: "%02d:%02d:%02d", p.tm_hour, p.tm_min, p.tm_sec)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
private func currentDate() -> String {
|
||||
var currentTime = time(nil)
|
||||
if let localTime = localtime(¤tTime) {
|
||||
let p = localTime.pointee
|
||||
return String(format: "%04d-%02d-%02d", p.tm_year + 1900, p.tm_mon + 1, p.tm_mday)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
@@ -32,7 +54,14 @@ final class Logger : NSObject, MP42Logging {
|
||||
|
||||
func write(toLog string: String) {
|
||||
queue.sync {
|
||||
let output = "\(currentTime()) \(string)\n"
|
||||
let prefix: String
|
||||
switch format {
|
||||
case .timeOnly:
|
||||
prefix = currentTime()
|
||||
case .dateAndTime:
|
||||
prefix = "\(currentDate()) \(currentTime())"
|
||||
}
|
||||
let output = "\(prefix) \(string)\n"
|
||||
|
||||
fileURL.withUnsafeFileSystemRepresentation {
|
||||
if let file = fopen($0, "a") {
|
||||
@@ -55,5 +84,38 @@ final class Logger : NSObject, MP42Logging {
|
||||
try? FileManager.default.removeItem(at: fileURL)
|
||||
}
|
||||
|
||||
static func defaultFormat() -> LogFormat {
|
||||
let logPref: Int = Prefs.logFormat
|
||||
return LogFormat(rawValue: logPref) ?? .timeOnly
|
||||
}
|
||||
|
||||
static func makeDefault() -> Logger {
|
||||
Logger(fileURL: defaultLogFile)
|
||||
}
|
||||
|
||||
static var defaultLogFile: URL = {
|
||||
let url = defaultDirectoryURL().appendingPathComponent("debugLog.txt")
|
||||
return url
|
||||
}()
|
||||
|
||||
static func defaultDirectoryURL() -> URL {
|
||||
let fileManager = FileManager.default
|
||||
if let url = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask)
|
||||
.first?.appendingPathComponent("Subler") {
|
||||
|
||||
do {
|
||||
if fileManager.fileExists(atPath: url.path) == false {
|
||||
try fileManager.createDirectory(at: url, withIntermediateDirectories: true, attributes: [:])
|
||||
}
|
||||
}
|
||||
catch _ {
|
||||
fatalError("Couldn't create the app support directory")
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
else {
|
||||
fatalError("Couldn't find the app support directory")
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -77,7 +77,8 @@ enum Prefs {
|
||||
_defaultSaveFormat, _organizeAlternateGroups, _inferMediaCharacteristics, _audioMixdown,
|
||||
_audioBitrate, _audioDRC, _audioConvertAC3, _audioKeepAC3, _audioConvertDts,
|
||||
_audioDtsOptions, _subtitleConvertBitmap, _ratingsCountry, _chaptersPreviewPosition,
|
||||
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1])
|
||||
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1,
|
||||
_logFormat])
|
||||
}
|
||||
|
||||
@Stored(key: "NSApplicationCrashOnException", defaultValue: true)
|
||||
@@ -160,6 +161,9 @@ enum Prefs {
|
||||
|
||||
@Stored(key: "SBPresetArtworkSelectorZoomLevel", defaultValue: 0)
|
||||
static var presetArtworkSelectorZoomLevel: Float
|
||||
|
||||
@Stored(key: "SBLogFormat", defaultValue: 0)
|
||||
static var logFormat: Int // 0 = Time Only, 1 = Date and Time
|
||||
}
|
||||
|
||||
enum MetadataPrefs {
|
||||
|
||||
@@ -28,6 +28,8 @@ final class Queue {
|
||||
|
||||
private let url: URL
|
||||
|
||||
private let logger = Logger.makeDefault()
|
||||
|
||||
enum Status {
|
||||
case unknown
|
||||
case working
|
||||
@@ -157,9 +159,12 @@ final class Queue {
|
||||
let result = self.process(currentItem)
|
||||
if .completed == result {
|
||||
completed += 1
|
||||
self.logger.write(toLog: currentItem.fileURL.lastPathComponent + " completed")
|
||||
} else if .failed == result {
|
||||
failed += 1
|
||||
self.logger.write(toLog: currentItem.fileURL.lastPathComponent + " failed")
|
||||
} else if .cancelled == result {
|
||||
self.logger.write(toLog: currentItem.fileURL.lastPathComponent + " cancelled")
|
||||
break
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user