Skip to content

Commit 6e29455

Browse files
committed
Merging latest changes from CocoaLumberjack project
1 parent b7ad73f commit 6e29455

File tree

10 files changed

+1741
-321
lines changed

10 files changed

+1741
-321
lines changed

Vendor/CocoaLumberjack/DDAbstractDatabaseLogger.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "DDAbstractDatabaseLogger.h"
2+
#import <math.h>
23

34
/**
45
* Welcome to Cocoa Lumberjack!
@@ -270,7 +271,10 @@ - (void)setSaveInterval:(NSTimeInterval)interval
270271
{
271272
dispatch_block_t block = ^{
272273

273-
if (saveInterval != interval)
274+
// C99 recommended floating point comparison macro
275+
// Read: isLessThanOrGreaterThan(floatA, floatB)
276+
277+
if (/* saveInterval != interval */ islessgreater(saveInterval, interval))
274278
{
275279
saveInterval = interval;
276280

@@ -350,7 +354,10 @@ - (void)setMaxAge:(NSTimeInterval)interval
350354
{
351355
dispatch_block_t block = ^{
352356

353-
if (maxAge != interval)
357+
// C99 recommended floating point comparison macro
358+
// Read: isLessThanOrGreaterThan(floatA, floatB)
359+
360+
if (/* maxAge != interval */ islessgreater(maxAge, interval))
354361
{
355362
NSTimeInterval oldMaxAge = maxAge;
356363
NSTimeInterval newMaxAge = interval;
@@ -436,7 +443,10 @@ - (void)setDeleteInterval:(NSTimeInterval)interval
436443
{
437444
dispatch_block_t block = ^{
438445

439-
if (deleteInterval != interval)
446+
// C99 recommended floating point comparison macro
447+
// Read: isLessThanOrGreaterThan(floatA, floatB)
448+
449+
if (/* deleteInterval != interval */ islessgreater(deleteInterval, interval))
440450
{
441451
deleteInterval = interval;
442452

Vendor/CocoaLumberjack/DDFileLogger.h

Lines changed: 102 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161

6262
// Public properties
6363

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+
**/
6472
@property (readwrite, assign) NSUInteger maximumNumberOfLogFiles;
6573

6674
// Public methods
@@ -92,18 +100,19 @@
92100
#pragma mark -
93101
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94102

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+
**/
107116
@interface DDLogFileManagerDefault : NSObject <DDLogFileManager>
108117
{
109118
NSUInteger maximumNumberOfLogFiles;
@@ -113,26 +122,46 @@
113122
- (id)init;
114123
- (id)initWithLogsDirectory:(NSString *)logsDirectory;
115124

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+
116141
@end
117142

118143
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119144
#pragma mark -
120145
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121146

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+
**/
131157
@interface DDLogFileFormatterDefault : NSObject <DDLogFormatter>
132158
{
133159
NSDateFormatter *dateFormatter;
134160
}
135161

162+
- (id)init;
163+
- (id)initWithDateFormatter:(NSDateFormatter *)dateFormatter;
164+
136165
@end
137166

138167
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -146,7 +175,7 @@
146175
DDLogFileInfo *currentLogFileInfo;
147176
NSFileHandle *currentLogFileHandle;
148177

149-
NSTimer *rollingTimer;
178+
dispatch_source_t rollingTimer;
150179

151180
unsigned long long maximumFileSize;
152181
NSTimeInterval rollingFrequency;
@@ -155,35 +184,46 @@
155184
- (id)init;
156185
- (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager;
157186

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+
**/
183218
@property (readwrite, assign) unsigned long long maximumFileSize;
184-
185219
@property (readwrite, assign) NSTimeInterval rollingFrequency;
186220

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+
**/
187227
@property (strong, nonatomic, readonly) id <DDLogFileManager> logFileManager;
188228

189229

@@ -202,19 +242,20 @@
202242
#pragma mark -
203243
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
204244

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+
**/
218259
@interface DDLogFileInfo : NSObject
219260
{
220261
__strong NSString *filePath;

0 commit comments

Comments
 (0)