No Description

DDAbstractDatabaseLogger.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2015, Deusty, LLC
  4. // All rights reserved.
  5. //
  6. // Redistribution and use of this software in source and binary forms,
  7. // with or without modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // * Neither the name of Deusty nor the names of its contributors may be used
  13. // to endorse or promote products derived from this software without specific
  14. // prior written permission of Deusty, LLC.
  15. // Disable legacy macros
  16. #ifndef DD_LEGACY_MACROS
  17. #define DD_LEGACY_MACROS 0
  18. #endif
  19. #import "DDLog.h"
  20. /**
  21. * This class provides an abstract implementation of a database logger.
  22. *
  23. * That is, it provides the base implementation for a database logger to build atop of.
  24. * All that is needed for a concrete database logger is to extend this class
  25. * and override the methods in the implementation file that are prefixed with "db_".
  26. **/
  27. @interface DDAbstractDatabaseLogger : DDAbstractLogger {
  28. @protected
  29. NSUInteger _saveThreshold;
  30. NSTimeInterval _saveInterval;
  31. NSTimeInterval _maxAge;
  32. NSTimeInterval _deleteInterval;
  33. BOOL _deleteOnEverySave;
  34. BOOL _saveTimerSuspended;
  35. NSUInteger _unsavedCount;
  36. dispatch_time_t _unsavedTime;
  37. dispatch_source_t _saveTimer;
  38. dispatch_time_t _lastDeleteTime;
  39. dispatch_source_t _deleteTimer;
  40. }
  41. /**
  42. * Specifies how often to save the data to disk.
  43. * Since saving is an expensive operation (disk io) it is not done after every log statement.
  44. * These properties allow you to configure how/when the logger saves to disk.
  45. *
  46. * A save is done when either (whichever happens first):
  47. *
  48. * - The number of unsaved log entries reaches saveThreshold
  49. * - The amount of time since the oldest unsaved log entry was created reaches saveInterval
  50. *
  51. * You can optionally disable the saveThreshold by setting it to zero.
  52. * If you disable the saveThreshold you are entirely dependent on the saveInterval.
  53. *
  54. * You can optionally disable the saveInterval by setting it to zero (or a negative value).
  55. * If you disable the saveInterval you are entirely dependent on the saveThreshold.
  56. *
  57. * It's not wise to disable both saveThreshold and saveInterval.
  58. *
  59. * The default saveThreshold is 500.
  60. * The default saveInterval is 60 seconds.
  61. **/
  62. @property (assign, readwrite) NSUInteger saveThreshold;
  63. @property (assign, readwrite) NSTimeInterval saveInterval;
  64. /**
  65. * It is likely you don't want the log entries to persist forever.
  66. * Doing so would allow the database to grow infinitely large over time.
  67. *
  68. * The maxAge property provides a way to specify how old a log statement can get
  69. * before it should get deleted from the database.
  70. *
  71. * The deleteInterval specifies how often to sweep for old log entries.
  72. * Since deleting is an expensive operation (disk io) is is done on a fixed interval.
  73. *
  74. * An alternative to the deleteInterval is the deleteOnEverySave option.
  75. * This specifies that old log entries should be deleted during every save operation.
  76. *
  77. * You can optionally disable the maxAge by setting it to zero (or a negative value).
  78. * If you disable the maxAge then old log statements are not deleted.
  79. *
  80. * You can optionally disable the deleteInterval by setting it to zero (or a negative value).
  81. *
  82. * If you disable both deleteInterval and deleteOnEverySave then old log statements are not deleted.
  83. *
  84. * It's not wise to enable both deleteInterval and deleteOnEverySave.
  85. *
  86. * The default maxAge is 7 days.
  87. * The default deleteInterval is 5 minutes.
  88. * The default deleteOnEverySave is NO.
  89. **/
  90. @property (assign, readwrite) NSTimeInterval maxAge;
  91. @property (assign, readwrite) NSTimeInterval deleteInterval;
  92. @property (assign, readwrite) BOOL deleteOnEverySave;
  93. /**
  94. * Forces a save of any pending log entries (flushes log entries to disk).
  95. **/
  96. - (void)savePendingLogEntries;
  97. /**
  98. * Removes any log entries that are older than maxAge.
  99. **/
  100. - (void)deleteOldLogEntries;
  101. @end