ORKDataLoggerManager Class Reference

Inherits from NSObject
Conforms to ORKDataLoggerDelegate
Declared in ORKDataLogger.h

The ORKDataLoggerManager class represents a manager for multiple ORKDataLogger instances, which tracks the total size of log files produced and can notify its delegate when file sizes reach configurable thresholds.

The ORKDataLoggerManager class is an internal component used by some ORKRecorder subclasses for writing data to disk during tasks.

This manager can be used to organize the ORKDataLogger logs in a directory, and keep track of the total number of bytes stored on disk by each logger. The delegate can be informed if either the number of bytes pending upload, or the total number of bytes, exceeds configurable thresholds.

The configuration of the loggers and their thresholds is persisted in a configuration file in the log directory.

If the number of bytes pending upload exceeds the threshold, the natural action is to upload them. A block-based enumeration is provided for enumerating all the logs pending upload. Use enumerateLogsNeedingUpload:error:, and when a log has been processed for upload, use the logger to mark it uploaded.

When the upload succeeds (or at least is successfully queued), the uploaded files can be removed across all the loggers by calling removeUploadedFiles:error:

If the total number of bytes exceeds the threshold, the natural action is to remove log files that have been marked uploaded, and then remove old log files until the threshold is no longer exceeded. You can do this by calling removeOldAndUploadedLogsToThreshold:error:

– initWithDirectory:delegate:

Returns an initialized data logger manager using the specified directory and delegate.

- (instancetype)initWithDirectory:(NSURL *)directory delegate:(nullable id<ORKDataLoggerManagerDelegate>)delegate

Parameters

directory

The file URL of the directory where the data loggers should coexist.

delegate

The delegate to receive notifications.

Return Value

An initialized data logger manager.

Discussion

Designated initializer.

Declared In

ORKDataLogger.h

  delegate

The delegate of the data logger manager.

@property (weak, nullable) id<ORKDataLoggerManagerDelegate> delegate

Declared In

ORKDataLogger.h

  pendingUploadBytesThreshold

The threshold for delegate callback for total bytes not marked uploaded.

@property unsigned long long pendingUploadBytesThreshold

Declared In

ORKDataLogger.h

  totalBytesThreshold

The threshold for delegate callback for total bytes of completed logs.

@property unsigned long long totalBytesThreshold

Declared In

ORKDataLogger.h

  pendingUploadBytes

The total number of bytes of files not marked as pending upload.

@property unsigned long long pendingUploadBytes

Declared In

ORKDataLogger.h

  totalBytes

The total number of bytes for all the loggers.

@property unsigned long long totalBytes

Declared In

ORKDataLogger.h

– addJSONDataLoggerForLogName:

Adds a data logger with a JSON log format to the directory.

- (ORKDataLogger *)addJSONDataLoggerForLogName:(NSString *)logName

Parameters

logName

The log name prefix for the data logger.

Return Value

The ORKDataLogger object that was added.

Discussion

This method throws an exception if a logger already exists with the specified log name.

Declared In

ORKDataLogger.h

– addDataLoggerForLogName:formatter:

Adds a data logger with a particular formatter to the directory.

- (ORKDataLogger *)addDataLoggerForLogName:(NSString *)logName formatter:(ORKLogFormatter *)formatter

Parameters

logName

The log name prefix for the data logger.

formatter

The log formatter instance to use for this logger.

Return Value

The ORKDataLogger object that was added, or the existing one if one already existed for that log name.

Declared In

ORKDataLogger.h

– dataLoggerForLogName:

Retrieves the already existing data logger for a log name.

- (nullable ORKDataLogger *)dataLoggerForLogName:(NSString *)logName

Parameters

logName

The log name prefix for the data logger.

Return Value

The ORKDataLogger object that was retrieved, or nil if one already existed for that log name.

Declared In

ORKDataLogger.h

– removeDataLogger:

Removes a data logger.

- (void)removeDataLogger:(ORKDataLogger *)logger

Parameters

logger

The logger to remove.

Declared In

ORKDataLogger.h

– logNames

Returns the set of log names of the data loggers managed by this object.

- (NSArray<NSString*> *)logNames

Declared In

ORKDataLogger.h

– enumerateLogsNeedingUpload:error:

Enumerates all the logs that need upload across all data loggers, sorted from oldest to first.

- (BOOL)enumerateLogsNeedingUpload:(void ( ^ ) ( ORKDataLogger *dataLogger , NSURL *logFileUrl , BOOL *stop ))block error:(NSError *__autoreleasing *)error

Parameters

block

The block to call during enumeration.

error

The error, on failure.

Return Value

YES if the enumeration succeeds; otherwise, NO.

Discussion

Before sorting the logs, this method fetches all the data loggers' logs that need upload.

Declared In

ORKDataLogger.h

– unmarkUploadedFiles:error:

Unmarks the set of uploaded files.

- (BOOL)unmarkUploadedFiles:(NSArray<NSURL*> *)fileURLs error:(NSError *_Nullable __autoreleasing *)error

Parameters

fileURLs

The array of file URLs that should no longer be marked uploaded.

error

The error, on failure.

Return Value

YES if the operation succeeds; otherwise, NO.

Discussion

Use this method to indicate that the specified files should no longer be marked uploaded (for example, because the upload did not succeed).

Declared In

ORKDataLogger.h

– removeUploadedFiles:error:

Removes a set of uploaded files.

- (BOOL)removeUploadedFiles:(NSArray<NSURL*> *)fileURLs error:(NSError *_Nullable __autoreleasing *)error

Parameters

fileURLs

The array of file URLs that should be removed.

error

The error, on failure.

Return Value

YES if the operation succeeds; otherwise, NO.

Discussion

This method is analogous to a similar method in ORKDataLogger, but it accepts an array of files that may relate to any of the data loggers. It is an error to pass a URL which would not belong to one of the loggers managed by this manager.

Declared In

ORKDataLogger.h

– removeOldAndUploadedLogsToThreshold:error:

Removes old and uploaded logs to bring total bytes down to a threshold.

- (BOOL)removeOldAndUploadedLogsToThreshold:(unsigned long long)bytes error:(NSError *_Nullable __autoreleasing *)error

Parameters

bytes

The threshold down to which to remove old log files. File removal stops when the total bytes managed by all the data loggers reaches this threshold.

error

The error, on failure.

Return Value

YES if the operation succeeds; otherwise, NO.

Discussion

This method removes uploaded logs first, followed by the oldest log files across all of the data loggers, until the total usage falls below a threshold.

Declared In

ORKDataLogger.h