diff --git a/Packages/App/Sources/AppUIMain/Views/Diagnostics/iOS/DebugLogContentView+iOS.swift b/Packages/App/Sources/AppUIMain/Views/Diagnostics/iOS/DebugLogContentView+iOS.swift deleted file mode 100644 index 564aebf5..00000000 --- a/Packages/App/Sources/AppUIMain/Views/Diagnostics/iOS/DebugLogContentView+iOS.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// DebugLogContentView+iOS.swift -// Passepartout -// -// Created by Davide De Rosa on 8/31/24. -// Copyright (c) 2025 Davide De Rosa. All rights reserved. -// -// https://github.com/passepartoutvpn -// -// This file is part of Passepartout. -// -// Passepartout is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Passepartout is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Passepartout. If not, see . -// - -#if os(iOS) - -import SwiftUI - -struct DebugLogContentView: View { - let lines: [String] - - var body: some View { - TextEditor(text: .constant(lines.joined(separator: "\n"))) - .font(.caption) - } -} - -#endif diff --git a/Packages/App/Sources/AppUIMain/Views/Diagnostics/macOS/DebugLogContentView+macOS.swift b/Packages/App/Sources/AppUIMain/Views/Diagnostics/macOS/DebugLogContentView+macOS.swift deleted file mode 100644 index 026d1dea..00000000 --- a/Packages/App/Sources/AppUIMain/Views/Diagnostics/macOS/DebugLogContentView+macOS.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// DebugLogContentView+macOS.swift -// Passepartout -// -// Created by Davide De Rosa on 8/31/24. -// Copyright (c) 2025 Davide De Rosa. All rights reserved. -// -// https://github.com/passepartoutvpn -// -// This file is part of Passepartout. -// -// Passepartout is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Passepartout is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Passepartout. If not, see . -// - -#if os(macOS) - -import SwiftUI - -struct DebugLogContentView: View { - let lines: [String] - - var body: some View { - List { - ForEach(Array(lines.enumerated()), id: \.offset) { - Text($0.element) - } - } - } -} - -#endif diff --git a/Packages/App/Sources/AppUITV/Views/Settings/DebugLogContentView.swift b/Packages/App/Sources/AppUITV/Views/Settings/DebugLogContentView.swift deleted file mode 100644 index 97775cee..00000000 --- a/Packages/App/Sources/AppUITV/Views/Settings/DebugLogContentView.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// DebugLogContentView.swift -// Passepartout -// -// Created by Davide De Rosa on 11/23/24. -// Copyright (c) 2025 Davide De Rosa. All rights reserved. -// -// https://github.com/passepartoutvpn -// -// This file is part of Passepartout. -// -// Passepartout is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Passepartout is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Passepartout. If not, see . -// - -import SwiftUI - -struct DebugLogContentView: View { - let lines: [String] - - var body: some View { - ScrollView { - LazyVStack { - ForEach(Array(lines.enumerated()), id: \.offset) { - Button($0.element) { - // - } - .buttonStyle(.plain) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.caption) - } - } - } - } -} diff --git a/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift b/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift index ce4f2796..711d3ac9 100644 --- a/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift +++ b/Packages/App/Sources/CommonLibrary/Business/ExtendedTunnel.swift @@ -122,7 +122,7 @@ extension ExtendedTunnel { public func currentLog(parameters: Constants.Log) async -> [String] { let output = try? await tunnel.sendMessage(.localLog( sinceLast: parameters.sinceLast, - maxLevel: parameters.maxLevel + maxLevel: parameters.options.maxLevel )) switch output { case .debugLog(let log): diff --git a/Packages/App/Sources/CommonLibrary/Domain/Constants.swift b/Packages/App/Sources/CommonLibrary/Domain/Constants.swift index bacb881c..d048581f 100644 --- a/Packages/App/Sources/CommonLibrary/Domain/Constants.swift +++ b/Packages/App/Sources/CommonLibrary/Domain/Constants.swift @@ -145,9 +145,7 @@ public struct Constants: Decodable, Sendable { public let sinceLast: TimeInterval - public let maxLevel: DebugLog.Level - - public let maxNumberOfLines: Int + public let options: LocalLogger.Options public let maxAge: TimeInterval? } diff --git a/Packages/App/Sources/CommonLibrary/Extensions/PassepartoutConfiguration+Logging.swift b/Packages/App/Sources/CommonLibrary/Extensions/PassepartoutConfiguration+Logging.swift index 7304d93d..46c6eec9 100644 --- a/Packages/App/Sources/CommonLibrary/Extensions/PassepartoutConfiguration+Logging.swift +++ b/Packages/App/Sources/CommonLibrary/Extensions/PassepartoutConfiguration+Logging.swift @@ -30,67 +30,27 @@ extension PassepartoutConfiguration { public func configureLogging(to url: URL, parameters: Constants.Log, logsPrivateData: Bool) { pp_log(.app, .debug, "Log to: \(url)") - setLocalLogger(options: .init( + setLocalLogger( url: url, - maxNumberOfLines: parameters.maxNumberOfLines, - maxLevel: parameters.maxLevel, + options: parameters.options, mapper: parameters.formatter.formattedLine - )) + ) if logsPrivateData { logsAddresses = true logsModules = true } - if let maxAge = parameters.maxAge { - purgeLogs(at: url, beyond: maxAge) - } + appendLog(parameters.options.maxLevel, message: "") + appendLog(parameters.options.maxLevel, message: "--- BEGIN ---") + appendLog(parameters.options.maxLevel, message: "") } public func currentLog(parameters: Constants.Log) -> [String] { currentLogLines( sinceLast: parameters.sinceLast, - maxLevel: parameters.maxLevel + maxLevel: parameters.options.maxLevel ) .map(parameters.formatter.formattedLine) } - - public func availableLogs(at url: URL) -> [Date: URL] { - let parent = url.deletingLastPathComponent() - let prefix = url.lastPathComponent - do { - let contents = try FileManager.default.contentsOfDirectory(at: parent, includingPropertiesForKeys: nil) - return contents.reduce(into: [:]) { found, item in - let filename = item.lastPathComponent - guard filename.hasPrefix(prefix) else { - return - } - guard let timestampString = filename.split(separator: ".").last, - let timestamp = TimeInterval(timestampString) else { - return - } - let date = Date(timeIntervalSince1970: timestamp) - found[date] = item - } - } catch { - return [:] - } - } - - public func flushLog() { - try? saveLog() - } -} - -private extension PassepartoutConfiguration { - func purgeLogs(at url: URL, beyond maxAge: TimeInterval) { - let logs = availableLogs(at: url) - let minDate = Date().addingTimeInterval(-maxAge) - logs.forEach { date, url in - guard date >= minDate else { - try? FileManager.default.removeItem(at: url) - return - } - } - } } diff --git a/Packages/App/Sources/CommonLibrary/Resources/Constants.json b/Packages/App/Sources/CommonLibrary/Resources/Constants.json index bf2ed0fa..7d115fca 100644 --- a/Packages/App/Sources/CommonLibrary/Resources/Constants.json +++ b/Packages/App/Sources/CommonLibrary/Resources/Constants.json @@ -37,9 +37,12 @@ "appPath": "app.log", "tunnelPath": "tunnel.log", "sinceLast": 86400, - "maxLevel": 3, - "maxNumberOfLines": 10000, - "maxAge": 604800, + "options": { + "maxLevel": 3, + "maxSize": 500000, + "maxBufferedLines": 5000, + "maxAge": 259200 + }, "formatter": { "timestamp": "HH:mm:ss", "message": "%@ - %@" diff --git a/Packages/App/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift b/Packages/App/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift index 312b2827..985bc677 100644 --- a/Packages/App/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift +++ b/Packages/App/Sources/UILibrary/Theme/UI/Theme+Modifiers.swift @@ -266,8 +266,23 @@ extension View { modifier(ThemeHoverListRowModifier()) } - public func themeTip(_ text: String, edge: Edge) -> some View { - modifier(ThemeTipModifier(text: text, edge: edge)) + public func themeTip