Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VPN logging logic #877

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ final class NetworkProtectionConnectionBandwidthAnalyzer {

os_log("Bytes per second in last time-interval: (rx: %{public}@, tx: %{public}@)",
log: .networkProtectionBandwidthAnalysis,
type: .info,
String(describing: rx), String(describing: tx))

idle = UInt64(rx) < Self.rxThreshold && UInt64(tx) < Self.txThreshold
Expand All @@ -103,7 +102,7 @@ final class NetworkProtectionConnectionBandwidthAnalyzer {
/// Useful when servers are swapped
///
func reset() {
os_log("Bandwidth analyzer reset", log: .networkProtectionBandwidthAnalysis, type: .info)
os_log("Bandwidth analyzer reset", log: .networkProtectionBandwidthAnalysis)
entries.removeAll()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ final class NetworkProtectionConnectionTester {
// After completing the connection tests we check if the tester is still supposed to be running
// to avoid giving results when it should not be running.
guard isRunning else {
os_log("Tester skipped returning results as it was stopped while running the tests", log: log, type: .info)
os_log("Tester skipped returning results as it was stopped while running the tests", log: log)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,31 @@ public actor NetworkProtectionTunnelFailureMonitor {
guard firstCheckSkipped else {
// Avoid running the first tunnel failure check after startup to avoid reading the first handshake after sleep, which will almost always
// be out of date. In normal operation, the first check will frequently be 0 as WireGuard hasn't had the chance to handshake yet.
os_log("⚫️ Skipping first tunnel failure check", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
os_log("⚫️ Skipping first tunnel failure check", log: .networkProtectionTunnelFailureMonitorLog)
firstCheckSkipped = true
return
}

let mostRecentHandshake = (try? await handshakeReporter.getMostRecentHandshake()) ?? 0

guard mostRecentHandshake > 0 else {
os_log("⚫️ Got handshake timestamp at or below 0, skipping check", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
os_log("⚫️ Got handshake timestamp at or below 0, skipping check", log: .networkProtectionTunnelFailureMonitorLog)
return
}

let difference = Date().timeIntervalSince1970 - mostRecentHandshake
os_log("⚫️ Last handshake: %{public}f seconds ago", log: .networkProtectionTunnelFailureMonitorLog, type: .debug, difference)
os_log("⚫️ Last handshake: %{public}f seconds ago", log: .networkProtectionTunnelFailureMonitorLog, difference)

if difference > Result.failureDetected.threshold, isConnected {
if failureReported {
os_log("⚫️ Tunnel failure already reported", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
os_log("⚫️ Tunnel failure already reported", log: .networkProtectionTunnelFailureMonitorLog)
} else {
os_log("⚫️ Tunnel failure reported", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
os_log("⚫️ Tunnel failure reported", log: .networkProtectionTunnelFailureMonitorLog)
callback(.failureDetected)
failureReported = true
}
} else if difference <= Result.failureRecovered.threshold, failureReported {
os_log("⚫️ Tunnel failure recovery", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
os_log("⚫️ Tunnel recovered from failure", log: .networkProtectionTunnelFailureMonitorLog)
callback(.failureRecovered)
failureReported = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class NetworkProtectionKeychainStore {
case errSecItemNotFound:
return nil
default:
os_log("🔵 SecItemCopyMatching status %{public}@", type: .error, String(describing: status))
os_log("🔴 SecItemCopyMatching status %{public}@", type: .error, String(describing: status))
throw NetworkProtectionKeychainStoreError.keychainReadError(field: name, status: status)
}
}
Expand Down
6 changes: 1 addition & 5 deletions Sources/NetworkProtection/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ extension OSLog {
Logging.networkProtectionTunnelFailureMonitorLoggingEnabled ? Logging.networkProtectionTunnelFailureMonitor : .disabled
}

public static var networkProtectionServerFailureRecoveryLog: OSLog {
Logging.networkProtectionServerFailureRecoveryLoggingEnabled ? Logging.networkProtectionServerFailureRecovery : .disabled
}

public static var networkProtectionConnectionTesterLog: OSLog {
Logging.networkProtectionConnectionTesterLoggingEnabled ? Logging.networkProtectionConnectionTesterLog : .disabled
}
Expand Down Expand Up @@ -84,7 +80,7 @@ extension OSLog {

struct Logging {

static let subsystem = "com.duckduckgo.macos.browser.network-protection"
static let subsystem = Bundle.main.bundleIdentifier!

fileprivate static let networkProtectionLoggingEnabled = true
fileprivate static let networkProtection: OSLog = OSLog(subsystem: subsystem, category: "Network Protection")
Expand Down
Loading
Loading