Skip to content

Logging Export

Mr.P edited this page Aug 29, 2026 · 2 revisions

Export Logs

Export retained file or XLFacility logs and share the generated file URLs from your application.

Prerequisites

  • The active destination is .file or .xlfacility.
  • The XLFacility plugin is installed when .xlfacility is selected.
  • At least one retained log is available.

API Reference

Framework

AIBudsLog.xcframework

Declaration

Swift

/// Exports all retained logs to one file.
/// - Parameter completion: Called with the exported path, optional beginning
///   and ending timestamps, and an error.
func exportLogs(_ completion: ((
                    _ filePath: String?,
                    _ logStartFrom: Date?,
                    _ logEndAt: Date?,
                    _ error: NSError?
                ) -> Void)?)

/// Exports retained logs to size-limited files.
/// - Parameters:
///   - maxFileSize: Maximum size of each exported file, in bytes.
///   - completion: Called with exported paths, optional beginning and ending
///     timestamps, and an error.
func exportLogs(_ maxFileSize: UInt64,
                   completion: ((
                       _ filePaths: [String]?,
                       _ logStartFrom: Date?,
                       _ logEndAt: Date?,
                       _ error: NSError?
                   ) -> Void)?)

Objective-C

/// Exports all retained logs to one file.
- (void)exportLogsWithCompletion:(void (^ _Nullable)(NSString * _Nullable, NSDate * _Nullable, NSDate * _Nullable, NSError * _Nullable))completion;

/// Exports retained logs to size-limited files.
- (void)exportLogsWithMaxFileSize:(uint64_t)maxFileSize
                       completion:(void (^ _Nullable)(NSArray<NSString *> * _Nullable, NSDate * _Nullable, NSDate * _Nullable, NSError * _Nullable))completion;

Both operations are defined by LogService and invoked on logService.

Usage Examples

Export One File

Swift

AIBudsLogSDK.logService.exportLogs { filePath, startDate, endDate, error in
    DispatchQueue.main.async {
        if let error {
            print("Export failed: \(error.localizedDescription)")
            return
        }

        guard let filePath else {
            print("Export completed without a file")
            return
        }

        print("Log range: \(String(describing: startDate))\(String(describing: endDate))")
        presentShareSheet(items: [URL(fileURLWithPath: filePath)])
    }
}

Objective-C

[AIBudsLogSDK.logService
    exportLogsWithCompletion:^(
        NSString *filePath, NSDate *startDate, NSDate *endDate, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (error != nil) {
                NSLog(@"Export failed: %@", error.localizedDescription);
                return;
            }
            if (filePath == nil) {
                NSLog(@"Export completed without a file");
                return;
            }

            NSURL *fileURL = [NSURL fileURLWithPath:filePath];
            [self presentShareSheetWithItems:@[ fileURL ]];
        });
    }];

Export Size-Limited Files

Swift

let fiveMegabytes: UInt64 = 5 * 1_000_000
AIBudsLogSDK.logService.exportLogs(fiveMegabytes) { paths, _, _, error in
    guard error == nil, let paths, !paths.isEmpty else { return }
    let URLs = paths.map(URL.init(fileURLWithPath:))
    DispatchQueue.main.async { presentShareSheet(items: URLs) }
}

Objective-C

uint64_t fiveMegabytes = 5 * 1000000;
[AIBudsLogSDK.logService exportLogsWithMaxFileSize:fiveMegabytes
                                        completion:^(NSArray<NSString *> *paths,
                                                     NSDate *startDate,
                                                     NSDate *endDate,
                                                     NSError *error) {
                                            if (error != nil || paths.count == 0) {
                                                return;
                                            }

                                            NSMutableArray<NSURL *> *URLs = [NSMutableArray array];
                                            for (NSString *path in paths) {
                                                [URLs addObject:[NSURL fileURLWithPath:path]];
                                            }
                                            dispatch_async(dispatch_get_main_queue(), ^{
                                                [self presentShareSheetWithItems:URLs];
                                            });
                                        }];

Notes

  • maxFileSize is expressed in bytes. The Demo converts decimal megabytes using 1_000_000 bytes per MB.
  • Export is unsupported for .console and .oslogger; switch to a persistent destination before collecting logs.
  • Treat an error as failure even when paths are returned, and treat an empty path collection as no export artifact.
  • Present UIActivityViewController on the main thread and configure its popover source on iPad.

AIBuds SDK iOS Wiki

Clone this wiki locally