|
| 1 | +#import <Foundation/Foundation.h> |
| 2 | + |
| 3 | +#import "DDLog.h" |
| 4 | + |
| 5 | +/** |
| 6 | + * Welcome to Cocoa Lumberjack! |
| 7 | + * |
| 8 | + * The Google Code page has a wealth of documentation if you have any questions. |
| 9 | + * http://code.google.com/p/cocoalumberjack/ |
| 10 | + * |
| 11 | + * If you're new to the project you may wish to read the "Getting Started" page. |
| 12 | + * http://code.google.com/p/cocoalumberjack/wiki/GettingStarted |
| 13 | + * |
| 14 | + * |
| 15 | + * This class provides an abstract implementation of a database logger. |
| 16 | + * |
| 17 | + * That is, it provides the base implementation for a database logger to build atop of. |
| 18 | + * All that is needed for a concrete database logger is to extend this class |
| 19 | + * and override the methods in the implementation file that are prefixed with "db_". |
| 20 | +**/ |
| 21 | + |
| 22 | +@interface DDAbstractDatabaseLogger : DDAbstractLogger { |
| 23 | +@protected |
| 24 | + NSUInteger saveThreshold; |
| 25 | + NSTimeInterval saveInterval; |
| 26 | + NSTimeInterval maxAge; |
| 27 | + NSTimeInterval deleteInterval; |
| 28 | + BOOL deleteOnEverySave; |
| 29 | + |
| 30 | + BOOL saveTimerSuspended; |
| 31 | + NSUInteger unsavedCount; |
| 32 | + dispatch_time_t unsavedTime; |
| 33 | + dispatch_source_t saveTimer; |
| 34 | + dispatch_time_t lastDeleteTime; |
| 35 | + dispatch_source_t deleteTimer; |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * Specifies how often to save the data to disk. |
| 40 | + * Since saving is an expensive operation (disk io) it is not done after every log statement. |
| 41 | + * These properties allow you to configure how/when the logger saves to disk. |
| 42 | + * |
| 43 | + * A save is done when either (whichever happens first): |
| 44 | + * |
| 45 | + * - The number of unsaved log entries reaches saveThreshold |
| 46 | + * - The amount of time since the oldest unsaved log entry was created reaches saveInterval |
| 47 | + * |
| 48 | + * You can optionally disable the saveThreshold by setting it to zero. |
| 49 | + * If you disable the saveThreshold you are entirely dependent on the saveInterval. |
| 50 | + * |
| 51 | + * You can optionally disable the saveInterval by setting it to zero (or a negative value). |
| 52 | + * If you disable the saveInterval you are entirely dependent on the saveThreshold. |
| 53 | + * |
| 54 | + * It's not wise to disable both saveThreshold and saveInterval. |
| 55 | + * |
| 56 | + * The default saveThreshold is 500. |
| 57 | + * The default saveInterval is 60 seconds. |
| 58 | +**/ |
| 59 | +@property (assign, readwrite) NSUInteger saveThreshold; |
| 60 | +@property (assign, readwrite) NSTimeInterval saveInterval; |
| 61 | + |
| 62 | +/** |
| 63 | + * It is likely you don't want the log entries to persist forever. |
| 64 | + * Doing so would allow the database to grow infinitely large over time. |
| 65 | + * |
| 66 | + * The maxAge property provides a way to specify how old a log statement can get |
| 67 | + * before it should get deleted from the database. |
| 68 | + * |
| 69 | + * The deleteInterval specifies how often to sweep for old log entries. |
| 70 | + * Since deleting is an expensive operation (disk io) is is done on a fixed interval. |
| 71 | + * |
| 72 | + * An alternative to the deleteInterval is the deleteOnEverySave option. |
| 73 | + * This specifies that old log entries should be deleted during every save operation. |
| 74 | + * |
| 75 | + * You can optionally disable the maxAge by setting it to zero (or a negative value). |
| 76 | + * If you disable the maxAge then old log statements are not deleted. |
| 77 | + * |
| 78 | + * You can optionally disable the deleteInterval by setting it to zero (or a negative value). |
| 79 | + * |
| 80 | + * If you disable both deleteInterval and deleteOnEverySave then old log statements are not deleted. |
| 81 | + * |
| 82 | + * It's not wise to enable both deleteInterval and deleteOnEverySave. |
| 83 | + * |
| 84 | + * The default maxAge is 7 days. |
| 85 | + * The default deleteInterval is 5 minutes. |
| 86 | + * The default deleteOnEverySave is NO. |
| 87 | +**/ |
| 88 | +@property (assign, readwrite) NSTimeInterval maxAge; |
| 89 | +@property (assign, readwrite) NSTimeInterval deleteInterval; |
| 90 | +@property (assign, readwrite) BOOL deleteOnEverySave; |
| 91 | + |
| 92 | +/** |
| 93 | + * Forces a save of any pending log entries (flushes log entries to disk). |
| 94 | +**/ |
| 95 | +- (void)savePendingLogEntries; |
| 96 | + |
| 97 | +/** |
| 98 | + * Removes any log entries that are older than maxAge. |
| 99 | +**/ |
| 100 | +- (void)deleteOldLogEntries; |
| 101 | + |
| 102 | +@end |
0 commit comments