Rename logError(…) to error(…)

This commit is contained in:
islam
2025-09-11 19:03:08 +01:00
parent 5d6aecfc83
commit b5382b129e
4 changed files with 22 additions and 22 deletions
@@ -160,7 +160,7 @@ final class SecureIdentityStateManager {
cache = try JSONDecoder().decode(IdentityCache.self, from: decryptedData) cache = try JSONDecoder().decode(IdentityCache.self, from: decryptedData)
} catch { } catch {
// Log error but continue with empty cache // Log error but continue with empty cache
SecureLogger.logError(error, context: "Failed to load identity cache", category: .security) SecureLogger.error(error, context: "Failed to load identity cache", category: .security)
} }
} }
@@ -194,7 +194,7 @@ final class SecureIdentityStateManager {
SecureLogger.debug("Identity cache saved to keychain", category: .security) SecureLogger.debug("Identity cache saved to keychain", category: .security)
} }
} catch { } catch {
SecureLogger.logError(error, context: "Failed to save identity cache", category: .security) SecureLogger.error(error, context: "Failed to save identity cache", category: .security)
} }
} }
+3 -3
View File
@@ -113,9 +113,9 @@ final class KeychainManager {
if status == errSecSuccess { return true } if status == errSecSuccess { return true }
if status == -34018 && !triedWithoutGroup { if status == -34018 && !triedWithoutGroup {
SecureLogger.logError(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) SecureLogger.error(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain)
} else if status != errSecDuplicateItem { } else if status != errSecDuplicateItem {
SecureLogger.logError(NSError(domain: "Keychain", code: Int(status)), context: "Error saving to keychain", category: .keychain) SecureLogger.error(NSError(domain: "Keychain", code: Int(status)), context: "Error saving to keychain", category: .keychain)
} }
return false return false
} }
@@ -151,7 +151,7 @@ final class KeychainManager {
if status == errSecSuccess { return result as? Data } if status == errSecSuccess { return result as? Data }
if status == -34018 { if status == -34018 {
SecureLogger.logError(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain) SecureLogger.error(NSError(domain: "Keychain", code: -34018), context: "Missing keychain entitlement", category: .keychain)
} }
return nil return nil
} }
@@ -281,7 +281,7 @@ final class NoiseEncryptionService {
let signature = try signingKey.signature(for: data) let signature = try signingKey.signature(for: data)
return signature return signature
} catch { } catch {
SecureLogger.logError(error, context: "Failed to sign data", category: .noise) SecureLogger.error(error, context: "Failed to sign data", category: .noise)
return nil return nil
} }
} }
@@ -292,7 +292,7 @@ final class NoiseEncryptionService {
let signingPublicKey = try Curve25519.Signing.PublicKey(rawRepresentation: publicKey) let signingPublicKey = try Curve25519.Signing.PublicKey(rawRepresentation: publicKey)
return signingPublicKey.isValidSignature(signature, for: data) return signingPublicKey.isValidSignature(signature, for: data)
} catch { } catch {
SecureLogger.logError(error, context: "Failed to verify signature", category: .noise) SecureLogger.error(error, context: "Failed to verify signature", category: .noise)
return false return false
} }
} }
@@ -578,7 +578,7 @@ final class NoiseEncryptionService {
// Signal that handshake is needed // Signal that handshake is needed
onHandshakeRequired?(peerID) onHandshakeRequired?(peerID)
} catch { } catch {
SecureLogger.logError(error, context: "Failed to initiate rekey for peer: \(peerID)", category: .session) SecureLogger.error(error, context: "Failed to initiate rekey for peer: \(peerID)", category: .session)
} }
} }
} }
+14 -14
View File
@@ -133,6 +133,20 @@ final class SecureLogger {
log(message(), category: category, level: .error, file: file, line: line, function: function) log(message(), category: category, level: .error, file: file, line: line, function: function)
} }
/// Log errors with context
static func error(_ error: Error, context: @autoclosure () -> String, category: OSLog = .noise,
file: String = #file, line: Int = #line, function: String = #function) {
let location = formatLocation(file: file, line: line, function: function)
let sanitized = sanitize(context())
let errorDesc = sanitize(error.localizedDescription)
#if DEBUG
os_log("%{public}@ Error in %{public}@: %{public}@", log: category, type: .error, location, sanitized, errorDesc)
#else
os_log("%{private}@ Error in %{private}@: %{private}@", log: category, type: .error, location, sanitized, errorDesc)
#endif
}
/// Log a security event /// Log a security event
static func logSecurityEvent(_ event: SecurityEvent, level: LogLevel = .info, static func logSecurityEvent(_ event: SecurityEvent, level: LogLevel = .info,
file: String = #file, line: Int = #line, function: String = #function) { file: String = #file, line: Int = #line, function: String = #function) {
@@ -148,20 +162,6 @@ final class SecureLogger {
#endif #endif
} }
/// Log errors with context
static func logError(_ error: Error, context: @autoclosure () -> String, category: OSLog = .noise,
file: String = #file, line: Int = #line, function: String = #function) {
let location = formatLocation(file: file, line: line, function: function)
let sanitized = sanitize(context())
let errorDesc = sanitize(error.localizedDescription)
#if DEBUG
os_log("%{public}@ Error in %{public}@: %{public}@", log: category, type: .error, location, sanitized, errorDesc)
#else
os_log("%{private}@ Error in %{private}@: %{private}@", log: category, type: .error, location, sanitized, errorDesc)
#endif
}
// MARK: - Private Helpers // MARK: - Private Helpers
/// Log general messages with automatic sensitive data filtering /// Log general messages with automatic sensitive data filtering