Skip to content

Commit

Permalink
Merging latest changes from CocoaLumberjack project
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Jun 8, 2012
1 parent b7ad73f commit 6e29455
Show file tree
Hide file tree
Showing 10 changed files with 1,741 additions and 321 deletions.
16 changes: 13 additions & 3 deletions Vendor/CocoaLumberjack/DDAbstractDatabaseLogger.m
@@ -1,4 +1,5 @@
#import "DDAbstractDatabaseLogger.h" #import "DDAbstractDatabaseLogger.h"
#import <math.h>


/** /**
* Welcome to Cocoa Lumberjack! * Welcome to Cocoa Lumberjack!
Expand Down Expand Up @@ -270,7 +271,10 @@ - (void)setSaveInterval:(NSTimeInterval)interval
{ {
dispatch_block_t block = ^{ dispatch_block_t block = ^{


if (saveInterval != interval) // C99 recommended floating point comparison macro
// Read: isLessThanOrGreaterThan(floatA, floatB)

if (/* saveInterval != interval */ islessgreater(saveInterval, interval))
{ {
saveInterval = interval; saveInterval = interval;


Expand Down Expand Up @@ -350,7 +354,10 @@ - (void)setMaxAge:(NSTimeInterval)interval
{ {
dispatch_block_t block = ^{ dispatch_block_t block = ^{


if (maxAge != interval) // C99 recommended floating point comparison macro
// Read: isLessThanOrGreaterThan(floatA, floatB)

if (/* maxAge != interval */ islessgreater(maxAge, interval))
{ {
NSTimeInterval oldMaxAge = maxAge; NSTimeInterval oldMaxAge = maxAge;
NSTimeInterval newMaxAge = interval; NSTimeInterval newMaxAge = interval;
Expand Down Expand Up @@ -436,7 +443,10 @@ - (void)setDeleteInterval:(NSTimeInterval)interval
{ {
dispatch_block_t block = ^{ dispatch_block_t block = ^{


if (deleteInterval != interval) // C99 recommended floating point comparison macro
// Read: isLessThanOrGreaterThan(floatA, floatB)

if (/* deleteInterval != interval */ islessgreater(deleteInterval, interval))
{ {
deleteInterval = interval; deleteInterval = interval;


Expand Down
163 changes: 102 additions & 61 deletions Vendor/CocoaLumberjack/DDFileLogger.h
Expand Up @@ -61,6 +61,14 @@


// Public properties // 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 deleting old/rolled/archived log files by setting this property to zero.
**/
@property (readwrite, assign) NSUInteger maximumNumberOfLogFiles; @property (readwrite, assign) NSUInteger maximumNumberOfLogFiles;


// Public methods // Public methods
Expand Down Expand Up @@ -92,18 +100,19 @@
#pragma mark - #pragma mark -
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Default log file manager. /**
// * Default log file manager.
// All log files are placed inside the logsDirectory. *
// If a specific logsDirectory isn't specified, the default directory is used. * All log files are placed inside the logsDirectory.
// On Mac, this is in ~/Library/Application Support/<Application Name>/Logs. * If a specific logsDirectory isn't specified, the default directory is used.
// On iPhone, this is in ~/Documents/Logs. * On Mac, this is in ~/Library/Logs/<Application Name>.
// * On iPhone, this is in ~/Library/Caches/Logs.
// Log files are named "log-<uuid>.txt", *
// where uuid is a 6 character hexadecimal consisting of the set [0123456789ABCDEF]. * Log files are named "log-<uuid>.txt",
// * where uuid is a 6 character hexadecimal consisting of the set [0123456789ABCDEF].
// Archived log files are automatically deleted according to the maximumNumberOfLogFiles property. *

* Archived log files are automatically deleted according to the maximumNumberOfLogFiles property.
**/
@interface DDLogFileManagerDefault : NSObject <DDLogFileManager> @interface DDLogFileManagerDefault : NSObject <DDLogFileManager>
{ {
NSUInteger maximumNumberOfLogFiles; NSUInteger maximumNumberOfLogFiles;
Expand All @@ -113,26 +122,46 @@
- (id)init; - (id)init;
- (id)initWithLogsDirectory:(NSString *)logsDirectory; - (id)initWithLogsDirectory:(NSString *)logsDirectory;


/* Inherited from DDLogFileManager protocol:
@property (readwrite, assign) NSUInteger maximumNumberOfLogFiles;
- (NSString *)logsDirectory;
- (NSArray *)unsortedLogFilePaths;
- (NSArray *)unsortedLogFileNames;
- (NSArray *)unsortedLogFileInfos;
- (NSArray *)sortedLogFilePaths;
- (NSArray *)sortedLogFileNames;
- (NSArray *)sortedLogFileInfos;
*/

@end @end


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - #pragma mark -
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// Most users will want file log messages to be prepended with the date and time. /**
// Rather than forcing the majority of users to write their own formatter, * Most users will want file log messages to be prepended with the date and time.
// we will supply a logical default formatter. * Rather than forcing the majority of users to write their own formatter,
// Users can easily replace this formatter with their own by invoking the setLogFormatter method. * we will supply a logical default formatter.
// It can also be removed by calling setLogFormatter, and passing a nil parameter. * Users can easily replace this formatter with their own by invoking the setLogFormatter method.
// * It can also be removed by calling setLogFormatter, and passing a nil parameter.
// In addition to the convenience of having a logical default formatter, *
// it will also provide a template that makes it easy for developers to copy and change. * In addition to the convenience of having a logical default formatter,

* it will also provide a template that makes it easy for developers to copy and change.
**/
@interface DDLogFileFormatterDefault : NSObject <DDLogFormatter> @interface DDLogFileFormatterDefault : NSObject <DDLogFormatter>
{ {
NSDateFormatter *dateFormatter; NSDateFormatter *dateFormatter;
} }


- (id)init;
- (id)initWithDateFormatter:(NSDateFormatter *)dateFormatter;

@end @end


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -146,7 +175,7 @@
DDLogFileInfo *currentLogFileInfo; DDLogFileInfo *currentLogFileInfo;
NSFileHandle *currentLogFileHandle; NSFileHandle *currentLogFileHandle;


NSTimer *rollingTimer; dispatch_source_t rollingTimer;


unsigned long long maximumFileSize; unsigned long long maximumFileSize;
NSTimeInterval rollingFrequency; NSTimeInterval rollingFrequency;
Expand All @@ -155,35 +184,46 @@
- (id)init; - (id)init;
- (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager; - (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager;


// Configuration /**
// * Log File Rolling:
// maximumFileSize: *
// The approximate maximum size to allow log files to grow. * maximumFileSize:
// If a log file is larger than this value after a write, * The approximate maximum size to allow log files to grow.
// then the log file is rolled. * If a log file is larger than this value after a log statement is appended,
// * then the log file is rolled.
// rollingFrequency *
// How often to roll the log file. * rollingFrequency
// The frequency is given as an NSTimeInterval, which is a double that specifies the interval in seconds. * How often to roll the log file.
// Once the log file gets to be this old, it is rolled. * The frequency is given as an NSTimeInterval, which is a double that specifies the interval in seconds.
// * Once the log file gets to be this old, it is rolled.
// Both the maximumFileSize and the rollingFrequency are used to manage rolling. *
// Whichever occurs first will cause the log file to be rolled. * Both the maximumFileSize and the rollingFrequency are used to manage rolling.
// * Whichever occurs first will cause the log file to be rolled.
// For example: *
// The rollingFrequency is 24 hours, * For example:
// but the log file surpasses the maximumFileSize after only 20 hours. * The rollingFrequency is 24 hours,
// The log file will be rolled at that 20 hour mark. * but the log file surpasses the maximumFileSize after only 20 hours.
// A new log file will be created, and the 24 hour timer will be restarted. * The log file will be rolled at that 20 hour mark.
// * A new log file will be created, and the 24 hour timer will be restarted.
// logFileManager *
// Allows you to retrieve the list of log files, * You may optionally disable rolling due to filesize by setting maximumFileSize to zero.
// and configure the maximum number of archived log files to keep. * If you do so, rolling is based solely on rollingFrequency.

*
* You may optionally disable rolling due to time by setting rollingFrequency to zero (or any non-positive number).
* If you do so, rolling is based solely on maximumFileSize.
*
* If you disable both maximumFileSize and rollingFrequency, then the log file won't ever be rolled.
* This is strongly discouraged.
**/
@property (readwrite, assign) unsigned long long maximumFileSize; @property (readwrite, assign) unsigned long long maximumFileSize;

@property (readwrite, assign) NSTimeInterval rollingFrequency; @property (readwrite, assign) NSTimeInterval rollingFrequency;


/**
* The DDLogFileManager instance can be used to retrieve the list of log files,
* and configure the maximum number of archived log files to keep.
*
* @see DDLogFileManager.maximumNumberOfLogFiles
**/
@property (strong, nonatomic, readonly) id <DDLogFileManager> logFileManager; @property (strong, nonatomic, readonly) id <DDLogFileManager> logFileManager;




Expand All @@ -202,19 +242,20 @@
#pragma mark - #pragma mark -
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// DDLogFileInfo is a simple class that provides access to various file attributes. /**
// It provides good performance as it only fetches the information if requested, * DDLogFileInfo is a simple class that provides access to various file attributes.
// and it caches the information to prevent duplicate fetches. * It provides good performance as it only fetches the information if requested,
// * and it caches the information to prevent duplicate fetches.
// It was designed to provide quick snapshots of the current state of log files, *
// and to help sort log files in an array. * It was designed to provide quick snapshots of the current state of log files,
// * and to help sort log files in an array.
// This class does not monitor the files, or update it's cached attribute values if the file changes on disk. *
// This is not what the class was designed for. * This class does not monitor the files, or update it's cached attribute values if the file changes on disk.
// * This is not what the class was designed for.
// If you absolutely must get updated values, *
// you can invoke the reset method which will clear the cache. * If you absolutely must get updated values,

* you can invoke the reset method which will clear the cache.
**/
@interface DDLogFileInfo : NSObject @interface DDLogFileInfo : NSObject
{ {
__strong NSString *filePath; __strong NSString *filePath;
Expand Down

0 comments on commit 6e29455

Please sign in to comment.