// Software License Agreement (BSD License) // // Copyright (c) 2010-2016, Deusty, LLC // All rights reserved. // // Redistribution and use of this software in source and binary forms, // with or without modification, are permitted provided that the following conditions are met: // // *Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // *Neither the name of Deusty nor the names of its contributors may be used // to endorse or promote products derived from this software without specific // prior written permission of Deusty, LLC. // Disable legacy macros #ifndef OBSDD_LEGACY_MACROS #define OBSDD_LEGACY_MACROS 0 #endif #import "OBSDDLog.h" @class OBSDDLogFileInfo; /** *This class provides a logger to write log statements to a file. **/ // Default configuration and safety/sanity values. // // maximumFileSize -> kOBSDDDefaultLogMaxFileSize // rollingFrequency -> kOBSDDDefaultLogRollingFrequency // maximumNumberOfLogFiles -> kOBSDDDefaultLogMaxNumLogFiles // logFilesDiskQuota -> kOBSDDDefaultLogFilesDiskQuota // // You should carefully consider the proper configuration values for your application. extern unsigned long long const kOBSDDDefaultLogMaxFileSize; extern NSTimeInterval const kOBSDDDefaultLogRollingFrequency; extern NSUInteger const kOBSDDDefaultLogMaxNumLogFiles; extern unsigned long long const kOBSDDDefaultLogFilesDiskQuota; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** * 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 `OBSDDLogFileInfo` objects. * The `OBSDDLogFileInfo` 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. */ @protocol OBSDDLogFileManager @required // Public properties /** *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. **/ @property (readwrite, assign, atomic) NSUInteger maximumNumberOfLogFiles; /** *The maximum space that logs can take. On rolling logfile all old logfiles that exceed logFilesDiskQuota will *be deleted. * *You may optionally disable this option by setting it to zero. **/ @property (readwrite, assign, atomic) unsigned long long logFilesDiskQuota; // Public methods /** * Returns the logs directory (path) */ @property (nonatomic, readonly, copy) NSString *logsDirectory; /** *Returns an array of `NSString` objects, *each of which is the filePath to an existing log file on disk. **/ @property (nonatomic, readonly, strong) NSArray *unsortedLogFilePaths; /** *Returns an array of `NSString` objects, *each of which is the fileName of an existing log file on disk. **/ @property (nonatomic, readonly, strong) NSArray *unsortedLogFileNames; /** *Returns an array of `OBSDDLogFileInfo` 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. **/ @property (nonatomic, readonly, strong) NSArray *unsortedLogFileInfos; /** *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. **/ @property (nonatomic, readonly, strong) NSArray *sortedLogFilePaths; /** *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. **/ @property (nonatomic, readonly, strong) NSArray *sortedLogFileNames; /** *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. **/ @property (nonatomic, readonly, strong) NSArray *sortedLogFileInfos; // Private methods (only to be used by OBSDDFileLogger) /** *Generates a new unique log file path, and creates the corresponding log file. **/ - (NSString *)createNewLogFile; @optional // Notifications from OBSDDFileLogger /** * Called when a log file was archieved */ - (void)didArchiveLogFile:(NSString *)logFilePath NS_SWIFT_NAME(didArchiveLogFile(atPath:)); /** * Called when the roll action was executed and the log was archieved */ - (void)didRollAndArchiveLogFile:(NSString *)logFilePath NS_SWIFT_NAME(didRollAndArchiveLogFile(atPath:)); @end //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** *Default log file manager. * *All log files are placed inside the logsDirectory. *If a specific logsDirectory isn't specified, the default directory is used. *On Mac, this is in `~/Library/Logs/`. *On iPhone, this is in `~/Library/Caches/Logs`. * *Log files are named `"