motion-logger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +3 -0
  3. data/README.md +48 -0
  4. data/Rakefile +15 -0
  5. data/app/app_delegate.rb +5 -0
  6. data/lib/logger/log.rb +85 -0
  7. data/lib/logger/version.rb +5 -0
  8. data/lib/motion-logger.rb +14 -0
  9. data/motion-logger.gemspec +19 -0
  10. data/spec/log_spec.rb +41 -0
  11. data/vendor/Podfile.lock +6 -0
  12. data/vendor/Pods/CocoaLumberjack/.gitignore +24 -0
  13. data/vendor/Pods/CocoaLumberjack/.hgignore +6 -0
  14. data/vendor/Pods/CocoaLumberjack/CocoaLumberjack.podspec +18 -0
  15. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
  16. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
  17. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
  18. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  19. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +618 -0
  20. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
  21. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1346 -0
  22. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +498 -0
  23. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +979 -0
  24. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +49 -0
  25. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +186 -0
  26. data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
  27. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
  28. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  29. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
  30. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +498 -0
  31. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +49 -0
  32. data/vendor/Pods/Pods-prefix.pch +3 -0
  33. data/vendor/Pods/Pods-resources.sh +15 -0
  34. data/vendor/Pods/Pods.bridgesupport +462 -0
  35. data/vendor/Pods/Pods.xcconfig +4 -0
  36. data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
  37. metadata +104 -0
@@ -0,0 +1,334 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "DDLog.h"
3
+
4
+ @class DDLogFileInfo;
5
+
6
+ /**
7
+ * Welcome to Cocoa Lumberjack!
8
+ *
9
+ * The project page has a wealth of documentation if you have any questions.
10
+ * https://github.com/robbiehanson/CocoaLumberjack
11
+ *
12
+ * If you're new to the project you may wish to read the "Getting Started" wiki.
13
+ * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
14
+ *
15
+ *
16
+ * This class provides a logger to write log statements to a file.
17
+ **/
18
+
19
+
20
+ // Default configuration and safety/sanity values.
21
+ //
22
+ // maximumFileSize -> DEFAULT_LOG_MAX_FILE_SIZE
23
+ // rollingFrequency -> DEFAULT_LOG_ROLLING_FREQUENCY
24
+ // maximumNumberOfLogFiles -> DEFAULT_LOG_MAX_NUM_LOG_FILES
25
+ //
26
+ // You should carefully consider the proper configuration values for your application.
27
+
28
+ #define DEFAULT_LOG_MAX_FILE_SIZE (1024 * 1024) // 1 MB
29
+ #define DEFAULT_LOG_ROLLING_FREQUENCY (60 * 60 * 24) // 24 Hours
30
+ #define DEFAULT_LOG_MAX_NUM_LOG_FILES (5) // 5 Files
31
+
32
+
33
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34
+ #pragma mark -
35
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36
+
37
+ // The LogFileManager protocol is designed to allow you to control all aspects of your log files.
38
+ //
39
+ // The primary purpose of this is to allow you to do something with the log files after they have been rolled.
40
+ // Perhaps you want to compress them to save disk space.
41
+ // Perhaps you want to upload them to an FTP server.
42
+ // Perhaps you want to run some analytics on the file.
43
+ //
44
+ // A default LogFileManager is, of course, provided.
45
+ // The default LogFileManager simply deletes old log files according to the maximumNumberOfLogFiles property.
46
+ //
47
+ // This protocol provides various methods to fetch the list of log files.
48
+ //
49
+ // There are two variants: sorted and unsorted.
50
+ // If sorting is not necessary, the unsorted variant is obviously faster.
51
+ // The sorted variant will return an array sorted by when the log files were created,
52
+ // with the most recently created log file at index 0, and the oldest log file at the end of the array.
53
+ //
54
+ // You can fetch only the log file paths (full path including name), log file names (name only),
55
+ // or an array of DDLogFileInfo objects.
56
+ // The DDLogFileInfo class is documented below, and provides a handy wrapper that
57
+ // gives you easy access to various file attributes such as the creation date or the file size.
58
+
59
+ @protocol DDLogFileManager <NSObject>
60
+ @required
61
+
62
+ // Public properties
63
+
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
+ **/
72
+ @property (readwrite, assign) NSUInteger maximumNumberOfLogFiles;
73
+
74
+ // Public methods
75
+
76
+ - (NSString *)logsDirectory;
77
+
78
+ - (NSArray *)unsortedLogFilePaths;
79
+ - (NSArray *)unsortedLogFileNames;
80
+ - (NSArray *)unsortedLogFileInfos;
81
+
82
+ - (NSArray *)sortedLogFilePaths;
83
+ - (NSArray *)sortedLogFileNames;
84
+ - (NSArray *)sortedLogFileInfos;
85
+
86
+ // Private methods (only to be used by DDFileLogger)
87
+
88
+ - (NSString *)createNewLogFile;
89
+
90
+ @optional
91
+
92
+ // Notifications from DDFileLogger
93
+
94
+ - (void)didArchiveLogFile:(NSString *)logFilePath;
95
+ - (void)didRollAndArchiveLogFile:(NSString *)logFilePath;
96
+
97
+ @end
98
+
99
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100
+ #pragma mark -
101
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102
+
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
+ **/
116
+ @interface DDLogFileManagerDefault : NSObject <DDLogFileManager>
117
+ {
118
+ NSUInteger maximumNumberOfLogFiles;
119
+ NSString *_logsDirectory;
120
+ }
121
+
122
+ - (id)init;
123
+ - (id)initWithLogsDirectory:(NSString *)logsDirectory;
124
+
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
+
141
+ @end
142
+
143
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144
+ #pragma mark -
145
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
146
+
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
+ **/
157
+ @interface DDLogFileFormatterDefault : NSObject <DDLogFormatter>
158
+ {
159
+ NSDateFormatter *dateFormatter;
160
+ }
161
+
162
+ - (id)init;
163
+ - (id)initWithDateFormatter:(NSDateFormatter *)dateFormatter;
164
+
165
+ @end
166
+
167
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
168
+ #pragma mark -
169
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
170
+
171
+ @interface DDFileLogger : DDAbstractLogger <DDLogger>
172
+ {
173
+ __strong id <DDLogFileManager> logFileManager;
174
+
175
+ DDLogFileInfo *currentLogFileInfo;
176
+ NSFileHandle *currentLogFileHandle;
177
+
178
+ dispatch_source_t rollingTimer;
179
+
180
+ unsigned long long maximumFileSize;
181
+ NSTimeInterval rollingFrequency;
182
+ }
183
+
184
+ - (id)init;
185
+ - (id)initWithLogFileManager:(id <DDLogFileManager>)logFileManager;
186
+
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
+ **/
218
+ @property (readwrite, assign) unsigned long long maximumFileSize;
219
+ @property (readwrite, assign) NSTimeInterval rollingFrequency;
220
+
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
+ **/
227
+ @property (strong, nonatomic, readonly) id <DDLogFileManager> logFileManager;
228
+
229
+
230
+ // You can optionally force the current log file to be rolled with this method.
231
+
232
+ - (void)rollLogFile;
233
+
234
+ // Inherited from DDAbstractLogger
235
+
236
+ // - (id <DDLogFormatter>)logFormatter;
237
+ // - (void)setLogFormatter:(id <DDLogFormatter>)formatter;
238
+
239
+ @end
240
+
241
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
242
+ #pragma mark -
243
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244
+
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
+ **/
259
+ @interface DDLogFileInfo : NSObject
260
+ {
261
+ __strong NSString *filePath;
262
+ __strong NSString *fileName;
263
+
264
+ __strong NSDictionary *fileAttributes;
265
+
266
+ __strong NSDate *creationDate;
267
+ __strong NSDate *modificationDate;
268
+
269
+ unsigned long long fileSize;
270
+ }
271
+
272
+ @property (strong, nonatomic, readonly) NSString *filePath;
273
+ @property (strong, nonatomic, readonly) NSString *fileName;
274
+
275
+ @property (strong, nonatomic, readonly) NSDictionary *fileAttributes;
276
+
277
+ @property (strong, nonatomic, readonly) NSDate *creationDate;
278
+ @property (strong, nonatomic, readonly) NSDate *modificationDate;
279
+
280
+ @property (nonatomic, readonly) unsigned long long fileSize;
281
+
282
+ @property (nonatomic, readonly) NSTimeInterval age;
283
+
284
+ @property (nonatomic, readwrite) BOOL isArchived;
285
+
286
+ + (id)logFileWithPath:(NSString *)filePath;
287
+
288
+ - (id)initWithFilePath:(NSString *)filePath;
289
+
290
+ - (void)reset;
291
+ - (void)renameFile:(NSString *)newFileName;
292
+
293
+ #if TARGET_IPHONE_SIMULATOR
294
+
295
+ // So here's the situation.
296
+ // Extended attributes are perfect for what we're trying to do here (marking files as archived).
297
+ // This is exactly what extended attributes were designed for.
298
+ //
299
+ // But Apple screws us over on the simulator.
300
+ // Everytime you build-and-go, they copy the application into a new folder on the hard drive,
301
+ // and as part of the process they strip extended attributes from our log files.
302
+ // Normally, a copy of a file preserves extended attributes.
303
+ // So obviously Apple has gone to great lengths to piss us off.
304
+ //
305
+ // Thus we use a slightly different tactic for marking log files as archived in the simulator.
306
+ // That way it "just works" and there's no confusion when testing.
307
+ //
308
+ // The difference in method names is indicative of the difference in functionality.
309
+ // On the simulator we add an attribute by appending a filename extension.
310
+ //
311
+ // For example:
312
+ // log-ABC123.txt -> log-ABC123.archived.txt
313
+
314
+ - (BOOL)hasExtensionAttributeWithName:(NSString *)attrName;
315
+
316
+ - (void)addExtensionAttributeWithName:(NSString *)attrName;
317
+ - (void)removeExtensionAttributeWithName:(NSString *)attrName;
318
+
319
+ #else
320
+
321
+ // Normal use of extended attributes used everywhere else,
322
+ // such as on Macs and on iPhone devices.
323
+
324
+ - (BOOL)hasExtendedAttributeWithName:(NSString *)attrName;
325
+
326
+ - (void)addExtendedAttributeWithName:(NSString *)attrName;
327
+ - (void)removeExtendedAttributeWithName:(NSString *)attrName;
328
+
329
+ #endif
330
+
331
+ - (NSComparisonResult)reverseCompareByCreationDate:(DDLogFileInfo *)another;
332
+ - (NSComparisonResult)reverseCompareByModificationDate:(DDLogFileInfo *)another;
333
+
334
+ @end