पुराने लॉग हटाएँ
निर्धारित दिनों से पुराने या किसी cutoff date से पहले के retained logs हटाएँ।
आवश्यक शर्तें
- Active log service persistent destination उपयोग करती है।
- उम्र के आधार पर हटाते समय
maxAgeशून्य से अधिक है।
API संदर्भ
Framework
AIBudsLog.xcframework
डिक्लेरेशन
- Swift
- Objective-C
/// 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)?)/// Purges log messages older than the specified maximum age.
- (void)purgeOldLogsWithMaxAge:(NSInteger)maxAge
completion:(void (^ _Nullable)(NSError * _Nullable))completion;
/// Purges log messages earlier than the specified timestamp.
- (void)purgeOldLogsBefore:(NSDate * _Nonnull)timestamp
completion:(void (^ _Nullable)(NSError * _Nullable))completion;purgeOldLogsWithMaxAge और purgeOldLogsBefore देखें।
उपयोग के उदाहरण
- Swift
- Objective-C
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 के आधार पर हटाएँ:let cutoff = Calendar.current.date(byAdding: .day, value: -7, to: Date())!
AIBudsLogSDK.logService.purgeOldLogsBefore(cutoff) { error in
if let error { print(error.localizedDescription) }
}
NSInteger retentionDays = 7;
[AIBudsLogSDK.logService
purgeOldLogsWithMaxAge:retentionDays
completion:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil) {
self.statusLabel.text = [NSString
stringWithFormat:@"Cleanup failed: %@", error.localizedDescription];
return;
}
self.statusLabel.text = @"Expired logs were deleted";
});
}];किसी निश्चित cutoff date के आधार पर हटाएँ:NSDate *cutoff = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay
value:-7
toDate:[NSDate date]
options:0];
[AIBudsLogSDK.logService purgeOldLogsBefore:cutoff
completion:^(NSError *error) {
if (error != nil) {
NSLog(@"%@", 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 जाँचें।