|
61 | 61 |
|
62 | 62 | // Public properties
|
63 | 63 |
|
| 64 | +/** |
| 65 | + * The maximum number of archived log files to keep on disk. |
| 66 | + * For example, if this property is set to 3, |
| 67 | + * then the LogFileManager will only keep 3 archived log files (plus the current active log file) on disk. |
| 68 | + * Once the active log file is rolled/archived, then the oldest of the existing 3 rolled/archived log files is deleted. |
| 69 | + * |
| 70 | + * You may optionally disable deleting old/rolled/archived log files by setting this property to zero. |
| 71 | +**/ |
64 | 72 | @property (readwrite, assign) NSUInteger maximumNumberOfLogFiles;
|
65 | 73 |
|
66 | 74 | // Public methods
|
|
92 | 100 | #pragma mark -
|
93 | 101 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
94 | 102 |
|
95 |
| -// Default log file manager. |
96 |
| -// |
97 |
| -// All log files are placed inside the logsDirectory. |
98 |
| -// If a specific logsDirectory isn't specified, the default directory is used. |
99 |
| -// On Mac, this is in ~/Library/Application Support/<Application Name>/Logs. |
100 |
| -// On iPhone, this is in ~/Documents/Logs. |
101 |
| -// |
102 |
| -// Log files are named "log-<uuid>.txt", |
103 |
| -// where uuid is a 6 character hexadecimal consisting of the set [0123456789ABCDEF]. |
104 |
| -// |
105 |
| -// Archived log files are automatically deleted according to the maximumNumberOfLogFiles property. |
106 |
| - |
| 103 | +/** |
| 104 | + * Default log file manager. |
| 105 | + * |
| 106 | + * All log files are placed inside the logsDirectory. |
| 107 | + * If a specific logsDirectory isn't specified, the default directory is used. |
| 108 | + * On Mac, this is in ~/Library/Logs/<Application Name>. |
| 109 | + * On iPhone, this is in ~/Library/Caches/Logs. |
| 110 | + * |
| 111 | + * Log files are named "log-<uuid>.txt", |
| 112 | + * where uuid is a 6 character hexadecimal consisting of the set [0123456789ABCDEF]. |
| 113 | + * |
| 114 | + * Archived log files are automatically deleted according to the maximumNumberOfLogFiles property. |
| 115 | +**/ |
107 | 116 | @interface DDLogFileManagerDefault : NSObject <DDLogFileManager>
|
108 | 117 | {
|
109 | 118 | NSUInteger maximumNumberOfLogFiles;
|
|
113 | 122 | - (id)init;
|
114 | 123 | - (id)initWithLogsDirectory:(NSString *)logsDirectory;
|
115 | 124 |
|
| 125 | +/* Inherited from DDLogFileManager protocol: |
| 126 | +
|
| 127 | +@property (readwrite, assign) NSUInteger maximumNumberOfLogFiles; |
| 128 | +
|
| 129 | +- (NSString *)logsDirectory; |
| 130 | +
|
| 131 | +- (NSArray *)unsortedLogFilePaths; |
| 132 | +- (NSArray *)unsortedLogFileNames; |
| 133 | +- (NSArray *)unsortedLogFileInfos; |
| 134 | +
|
| 135 | +- (NSArray *)sortedLogFilePaths; |
| 136 | +- (NSArray *)sortedLogFileNames; |
| 137 | +- (NSArray *)sortedLogFileInfos; |
| 138 | +
|
| 139 | +*/ |
| 140 | + |
116 | 141 | @end
|
117 | 142 |
|
118 | 143 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
119 | 144 | #pragma mark -
|
120 | 145 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
121 | 146 |
|
122 |
| -// Most users will want file log messages to be prepended with the date and time. |
123 |
| -// Rather than forcing the majority of users to write their own formatter, |
124 |
| -// we will supply a logical default formatter. |
125 |
| -// Users can easily replace this formatter with their own by invoking the setLogFormatter method. |
126 |
| -// It can also be removed by calling setLogFormatter, and passing a nil parameter. |
127 |
| -// |
128 |
| -// In addition to the convenience of having a logical default formatter, |
129 |
| -// it will also provide a template that makes it easy for developers to copy and change. |
130 |
| - |
| 147 | +/** |
| 148 | + * Most users will want file log messages to be prepended with the date and time. |
| 149 | + * Rather than forcing the majority of users to write their own formatter, |
| 150 | + * we will supply a logical default formatter. |
| 151 | + * Users can easily replace this formatter with their own by invoking the setLogFormatter method. |
| 152 | + * It can also be removed by calling setLogFormatter, and passing a nil parameter. |
| 153 | + * |
| 154 | + * In addition to the convenience of having a logical default formatter, |
| 155 | + * it will also provide a template that makes it easy for developers to copy and change. |
| 156 | +**/ |
131 | 157 | @interface DDLogFileFormatterDefault : NSObject <DDLogFormatter>
|
132 | 158 | {
|
133 | 159 | NSDateFormatter *dateFormatter;
|
134 | 160 | }
|
135 | 161 |
|
| 162 | +- (id)init; |
| 163 | +- (id)initWithDateFormatter:(NSDateFormatter *)dateFormatter; |
| 164 | + |
136 | 165 | @end
|
137 | 166 |
|
138 | 167 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
146 | 175 | DDLogFileInfo *currentLogFileInfo;
|
147 | 176 | NSFileHandle *currentLogFileHandle;
|
148 | 177 |
|
149 |
| - NSTimer *rollingTimer; |
| 178 | + dispatch_source_t rollingTimer; |
150 | 179 |
|
151 | 180 | unsigned long long maximumFileSize;
|
152 | 181 | NSTimeInterval rollingFrequency;
|
|
155 | 184 | - (id)init;
|
156 | 185 | - (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager;
|
157 | 186 |
|
158 |
| -// Configuration |
159 |
| -// |
160 |
| -// maximumFileSize: |
161 |
| -// The approximate maximum size to allow log files to grow. |
162 |
| -// If a log file is larger than this value after a write, |
163 |
| -// then the log file is rolled. |
164 |
| -// |
165 |
| -// rollingFrequency |
166 |
| -// How often to roll the log file. |
167 |
| -// The frequency is given as an NSTimeInterval, which is a double that specifies the interval in seconds. |
168 |
| -// Once the log file gets to be this old, it is rolled. |
169 |
| -// |
170 |
| -// Both the maximumFileSize and the rollingFrequency are used to manage rolling. |
171 |
| -// Whichever occurs first will cause the log file to be rolled. |
172 |
| -// |
173 |
| -// For example: |
174 |
| -// The rollingFrequency is 24 hours, |
175 |
| -// but the log file surpasses the maximumFileSize after only 20 hours. |
176 |
| -// The log file will be rolled at that 20 hour mark. |
177 |
| -// A new log file will be created, and the 24 hour timer will be restarted. |
178 |
| -// |
179 |
| -// logFileManager |
180 |
| -// Allows you to retrieve the list of log files, |
181 |
| -// and configure the maximum number of archived log files to keep. |
182 |
| - |
| 187 | +/** |
| 188 | + * Log File Rolling: |
| 189 | + * |
| 190 | + * maximumFileSize: |
| 191 | + * The approximate maximum size to allow log files to grow. |
| 192 | + * If a log file is larger than this value after a log statement is appended, |
| 193 | + * then the log file is rolled. |
| 194 | + * |
| 195 | + * rollingFrequency |
| 196 | + * How often to roll the log file. |
| 197 | + * The frequency is given as an NSTimeInterval, which is a double that specifies the interval in seconds. |
| 198 | + * Once the log file gets to be this old, it is rolled. |
| 199 | + * |
| 200 | + * Both the maximumFileSize and the rollingFrequency are used to manage rolling. |
| 201 | + * Whichever occurs first will cause the log file to be rolled. |
| 202 | + * |
| 203 | + * For example: |
| 204 | + * The rollingFrequency is 24 hours, |
| 205 | + * but the log file surpasses the maximumFileSize after only 20 hours. |
| 206 | + * The log file will be rolled at that 20 hour mark. |
| 207 | + * A new log file will be created, and the 24 hour timer will be restarted. |
| 208 | + * |
| 209 | + * You may optionally disable rolling due to filesize by setting maximumFileSize to zero. |
| 210 | + * If you do so, rolling is based solely on rollingFrequency. |
| 211 | + * |
| 212 | + * You may optionally disable rolling due to time by setting rollingFrequency to zero (or any non-positive number). |
| 213 | + * If you do so, rolling is based solely on maximumFileSize. |
| 214 | + * |
| 215 | + * If you disable both maximumFileSize and rollingFrequency, then the log file won't ever be rolled. |
| 216 | + * This is strongly discouraged. |
| 217 | +**/ |
183 | 218 | @property (readwrite, assign) unsigned long long maximumFileSize;
|
184 |
| - |
185 | 219 | @property (readwrite, assign) NSTimeInterval rollingFrequency;
|
186 | 220 |
|
| 221 | +/** |
| 222 | + * The DDLogFileManager instance can be used to retrieve the list of log files, |
| 223 | + * and configure the maximum number of archived log files to keep. |
| 224 | + * |
| 225 | + * @see DDLogFileManager.maximumNumberOfLogFiles |
| 226 | +**/ |
187 | 227 | @property (strong, nonatomic, readonly) id <DDLogFileManager> logFileManager;
|
188 | 228 |
|
189 | 229 |
|
|
202 | 242 | #pragma mark -
|
203 | 243 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
204 | 244 |
|
205 |
| -// DDLogFileInfo is a simple class that provides access to various file attributes. |
206 |
| -// It provides good performance as it only fetches the information if requested, |
207 |
| -// and it caches the information to prevent duplicate fetches. |
208 |
| -// |
209 |
| -// It was designed to provide quick snapshots of the current state of log files, |
210 |
| -// and to help sort log files in an array. |
211 |
| -// |
212 |
| -// This class does not monitor the files, or update it's cached attribute values if the file changes on disk. |
213 |
| -// This is not what the class was designed for. |
214 |
| -// |
215 |
| -// If you absolutely must get updated values, |
216 |
| -// you can invoke the reset method which will clear the cache. |
217 |
| - |
| 245 | +/** |
| 246 | + * DDLogFileInfo is a simple class that provides access to various file attributes. |
| 247 | + * It provides good performance as it only fetches the information if requested, |
| 248 | + * and it caches the information to prevent duplicate fetches. |
| 249 | + * |
| 250 | + * It was designed to provide quick snapshots of the current state of log files, |
| 251 | + * and to help sort log files in an array. |
| 252 | + * |
| 253 | + * This class does not monitor the files, or update it's cached attribute values if the file changes on disk. |
| 254 | + * This is not what the class was designed for. |
| 255 | + * |
| 256 | + * If you absolutely must get updated values, |
| 257 | + * you can invoke the reset method which will clear the cache. |
| 258 | +**/ |
218 | 259 | @interface DDLogFileInfo : NSObject
|
219 | 260 | {
|
220 | 261 | __strong NSString *filePath;
|
|
0 commit comments