만료된 로그 삭제
지정한 일수보다 오래됐거나 특정 기준 날짜 이전에 생성된 로그를 삭제합니다.
사전 요구 사항
- 현재 로그 서비스가 영구 저장을 지원하는 출력 대상을 사용해야 합니다.
- 보관 기간을 기준으로 삭제하려면
maxAge가 0보다 커야 합니다.
API Reference
프레임워크
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"
}
}기준 날짜를 직접 지정해 삭제하려면 다음과 같이 호출합니다.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";
});
}];기준 날짜를 직접 지정해 삭제하려면 다음과 같이 호출합니다.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);
}
}];
참고
AIBudsLogSDK.setXLFacilityPlugin(_:)는 플러그인을 불러올 때 현재logFileMaxAge를 기준으로 XLFacility 로그를 자동 정리합니다.logFileMaxAge를 변경하면 보관 기간만 갱신되며 즉시 정리가 실행되지는 않습니다. 바로 삭제해야 한다면 purge 메서드를 호출하세요.- purge 작업은 현재 로그 서비스에 저장된 데이터에만 적용됩니다. Console과 OS Logger 출력은 앱에서 관리하는 저장소가 아닙니다.
- 백그라운드 정리가 성공했다고 가정하지 말고 완료 콜백의 결과를 확인하세요.