DDLogFileManager
Objective-C
@protocol DDLogFileManager <NSObject>
Swift
protocol DDLogFileManager : NSObjectProtocol
The LogFileManager protocol is designed to allow you to control all aspects of your log files.
The primary purpose of this is to allow you to do something with the log files after they have been rolled. Perhaps you want to compress them to save disk space. Perhaps you want to upload them to an FTP server. Perhaps you want to run some analytics on the file.
A default LogFileManager is, of course, provided. The default LogFileManager simply deletes old log files according to the maximumNumberOfLogFiles property.
This protocol provides various methods to fetch the list of log files.
There are two variants: sorted and unsorted. If sorting is not necessary, the unsorted variant is obviously faster. The sorted variant will return an array sorted by when the log files were created, with the most recently created log file at index 0, and the oldest log file at the end of the array.
You can fetch only the log file paths (full path including name), log file names (name only),
or an array of DDLogFileInfo
objects.
The DDLogFileInfo
class is documented below, and provides a handy wrapper that
gives you easy access to various file attributes such as the creation date or the file size.
-
The maximum number of archived log files to keep on disk. For example, if this property is set to 3, then the LogFileManager will only keep 3 archived log files (plus the current active log file) on disk. Once the active log file is rolled/archived, then the oldest of the existing 3 rolled/archived log files is deleted.
You may optionally disable this option by setting it to zero.
Declaration
Objective-C
@required @property (atomic, assign, unsafe_unretained, readwrite) NSUInteger maximumNumberOfLogFiles;
Swift
var maximumNumberOfLogFiles: UInt { get set }
-
The maximum space that logs can take. On rolling logfile all old log files that exceed logFilesDiskQuota will be deleted.
You may optionally disable this option by setting it to zero.
Declaration
Objective-C
@required @property (atomic, assign, unsafe_unretained, readwrite) unsigned long long logFilesDiskQuota;
Swift
var logFilesDiskQuota: UInt64 { get set }
-
Returns the logs directory (path)
Declaration
Objective-C
@required @property (nonatomic, copy, readonly) NSString *_Nonnull logsDirectory;
Swift
var logsDirectory: String { get }
-
Returns an array of
NSString
objects, each of which is the filePath to an existing log file on disk.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<NSString *> *_Nonnull unsortedLogFilePaths;
Swift
var unsortedLogFilePaths: [String] { get }
-
Returns an array of
NSString
objects, each of which is the fileName of an existing log file on disk.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<NSString *> *_Nonnull unsortedLogFileNames;
Swift
var unsortedLogFileNames: [String] { get }
-
Returns an array of
DDLogFileInfo
objects, each representing an existing log file on disk, and containing important information about the log file such as it’s modification date and size.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<DDLogFileInfo *> *_Nonnull unsortedLogFileInfos;
Swift
var unsortedLogFileInfos: [DDLogFileInfo] { get }
-
Just like the
unsortedLogFilePaths
method, but sorts the array. The items in the array are sorted by creation date. The first item in the array will be the most recently created log file.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<NSString *> *_Nonnull sortedLogFilePaths;
Swift
var sortedLogFilePaths: [String] { get }
-
Just like the
unsortedLogFileNames
method, but sorts the array. The items in the array are sorted by creation date. The first item in the array will be the most recently created log file.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<NSString *> *_Nonnull sortedLogFileNames;
Swift
var sortedLogFileNames: [String] { get }
-
Just like the
unsortedLogFileInfos
method, but sorts the array. The items in the array are sorted by creation date. The first item in the array will be the most recently created log file.Declaration
Objective-C
@required @property (nonatomic, strong, readonly) NSArray<DDLogFileInfo *> *_Nonnull sortedLogFileInfos;
Swift
var sortedLogFileInfos: [DDLogFileInfo] { get }
-
Generates a new unique log file path, and creates the corresponding log file. This method is executed directly on the file logger’s internal queue. The file has to exist by the time the method returns.
Declaration
Objective-C
- (nullable NSString *)createNewLogFileWithError: (NSError *_Nullable *_Nullable)error;
Swift
func createNewLogFile() throws -> String
-
Deprecated
Use -createNewLogFileWithError:
Creates a new log file ignoring any errors. Deprecated in favor of
-createNewLogFileWithError:
. Will only be called if-createNewLogFileWithError:
is not implemented.Declaration
Objective-C
- (nullable NSString *)createNewLogFile;
-
Called when a log file was archived. Executed on global queue with default priority.
Declaration
Objective-C
- (void)didArchiveLogFile:(nonnull NSString *)logFilePath wasRolled:(BOOL)wasRolled;
Swift
optional func didArchiveLogFile(atPath logFilePath: String, wasRolled: Bool)
Parameters
logFilePath
The path to the log file that was archived.
wasRolled
Whether or not the archiving happend after rolling the log file.
-
Deprecated
Use -didArchiveLogFile:wasRolled:
Called when a log file was archived. Executed on global queue with default priority.
Declaration
Objective-C
- (void)didArchiveLogFile:(nonnull NSString *)logFilePath;
Swift
optional func didArchiveLogFile(atPath logFilePath: String)
-
Deprecated
Use -didArchiveLogFile:wasRolled:
Called when the roll action was executed and the log was archived. Executed on global queue with default priority.
Declaration
Objective-C
- (void)didRollAndArchiveLogFile:(nonnull NSString *)logFilePath;
Swift
optional func didRollAndArchiveLogFile(atPath logFilePath: String)