DDAbstractDatabaseLogger.h 3.6 KB

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