मुख्य कंटेंट तक स्किप करें

पुराने लॉग हटाएँ

निर्धारित दिनों से पुराने या किसी cutoff date से पहले के retained logs हटाएँ।

आवश्यक शर्तें

  • Active log service persistent destination उपयोग करती है।
  • उम्र के आधार पर हटाते समय maxAge शून्य से अधिक है।

API संदर्भ

Framework

AIBudsLog.xcframework

डिक्लेरेशन

Swift
/// Purges log messages older than the specified maximum age.
/// - Parameters:
///   - maxAge: Retention age in days.
///   - completion: Called with an error, or `nil` on success.
func purgeOldLogsWithMaxAge(_ maxAge: Int, completion: ((_ error: NSError?) -> Void)?)

/// Purges log messages earlier than the specified timestamp.
/// - Parameters:
///   - timestamp: The exclusive cutoff date for retained logs.
///   - completion: Called with an error, or `nil` on success.
func purgeOldLogsBefore(_ timestamp: Date, completion: ((_ error: NSError?) -> Void)?)

purgeOldLogsWithMaxAge और purgeOldLogsBefore देखें।

उपयोग के उदाहरण

Swift
let retentionDays = 7

AIBudsLogSDK.logService.purgeOldLogsWithMaxAge(retentionDays) { error in
    DispatchQueue.main.async {
        if let error {
            statusLabel.text = "Cleanup failed: \(error.localizedDescription)"
            return
        }
        statusLabel.text = "Logs older than \(retentionDays) days were deleted"
    }
}

किसी निश्चित cutoff date के आधार पर हटाएँ:

Swift
let cutoff = Calendar.current.date(byAdding: .day, value: -7, to: Date())!
AIBudsLogSDK.logService.purgeOldLogsBefore(cutoff) { error in
    if let error { print(error.localizedDescription) }
}

ध्यान दें

  • Plugin load होने पर AIBudsLogSDK.setXLFacilityPlugin(_:) वर्तमान logFileMaxAge के आधार पर XLFacility logs अपने-आप purge करता है।
  • logFileMaxAge बदलने से retention configure होता है, तुरंत cleanup नहीं चलता। तुरंत हटाना हो तो purge method call करें।
  • Purge operations active log service के retained data पर लागू होते हैं; console और OS Logger output app-managed retained stores नहीं हैं।
  • Background cleanup सफल मान लेने के बजाय completion callback जाँचें।