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,49 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ #import "DDLog.h"
4
+
5
+ /**
6
+ * Welcome to Cocoa Lumberjack!
7
+ *
8
+ * The project page has a wealth of documentation if you have any questions.
9
+ * https://github.com/robbiehanson/CocoaLumberjack
10
+ *
11
+ * If you're new to the project you may wish to read the "Getting Started" wiki.
12
+ * https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
13
+ *
14
+ *
15
+ * This class provides a logger for Terminal output or Xcode console output,
16
+ * depending on where you are running your code.
17
+ *
18
+ * As described in the "Getting Started" page,
19
+ * the traditional NSLog() function directs it's output to two places:
20
+ *
21
+ * - Apple System Log (so it shows up in Console.app)
22
+ * - StdErr (if stderr is a TTY, so log statements show up in Xcode console)
23
+ *
24
+ * To duplicate NSLog() functionality you can simply add this logger and an asl logger.
25
+ * However, if you instead choose to use file logging (for faster performance),
26
+ * you may choose to use only a file logger and a tty logger.
27
+ **/
28
+
29
+ @interface DDTTYLogger : DDAbstractLogger <DDLogger>
30
+ {
31
+ BOOL isaTTY;
32
+
33
+ NSDateFormatter *dateFormatter;
34
+
35
+ char *app; // Not null terminated
36
+ char *pid; // Not null terminated
37
+
38
+ size_t appLen;
39
+ size_t pidLen;
40
+ }
41
+
42
+ + (DDTTYLogger *)sharedInstance;
43
+
44
+ // Inherited from DDAbstractLogger
45
+
46
+ // - (id <DDLogFormatter>)logFormatter;
47
+ // - (void)setLogFormatter:(id <DDLogFormatter>)formatter;
48
+
49
+ @end
@@ -0,0 +1,186 @@
1
+ #import "DDTTYLogger.h"
2
+
3
+ #import <unistd.h>
4
+ #import <sys/uio.h>
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
+ #if ! __has_feature(objc_arc)
17
+ #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
18
+ #endif
19
+
20
+
21
+ @implementation DDTTYLogger
22
+
23
+ static DDTTYLogger *sharedInstance;
24
+
25
+ /**
26
+ * The runtime sends initialize to each class in a program exactly one time just before the class,
27
+ * or any class that inherits from it, is sent its first message from within the program. (Thus the
28
+ * method may never be invoked if the class is not used.) The runtime sends the initialize message to
29
+ * classes in a thread-safe manner. Superclasses receive this message before their subclasses.
30
+ *
31
+ * This method may also be called directly (assumably by accident), hence the safety mechanism.
32
+ **/
33
+ + (void)initialize
34
+ {
35
+ static BOOL initialized = NO;
36
+ if (!initialized)
37
+ {
38
+ initialized = YES;
39
+
40
+ sharedInstance = [[DDTTYLogger alloc] init];
41
+ }
42
+ }
43
+
44
+ + (DDTTYLogger *)sharedInstance
45
+ {
46
+ return sharedInstance;
47
+ }
48
+
49
+ - (id)init
50
+ {
51
+ if (sharedInstance != nil)
52
+ {
53
+ return nil;
54
+ }
55
+
56
+ if ((self = [super init]))
57
+ {
58
+ isaTTY = isatty(STDERR_FILENO);
59
+
60
+ if (isaTTY)
61
+ {
62
+ dateFormatter = [[NSDateFormatter alloc] init];
63
+ [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
64
+ [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SSS"];
65
+
66
+ // Initialze 'app' variable (char *)
67
+
68
+ NSString *appNStr = [[NSProcessInfo processInfo] processName];
69
+ const char *appCStr = [appNStr UTF8String];
70
+
71
+ appLen = strlen(appCStr);
72
+
73
+ app = (char *)malloc(appLen);
74
+ strncpy(app, appCStr, appLen); // Not null terminated
75
+
76
+ // Initialize 'pid' variable (char *)
77
+
78
+ NSString *pidNStr = [NSString stringWithFormat:@"%i", (int)getpid()];
79
+ const char *pidCStr = [pidNStr UTF8String];
80
+
81
+ pidLen = strlen(pidCStr);
82
+
83
+ pid = (char *)malloc(pidLen);
84
+ strncpy(pid, pidCStr, pidLen); // Not null terminated
85
+ }
86
+ }
87
+ return self;
88
+ }
89
+
90
+ - (void)logMessage:(DDLogMessage *)logMessage
91
+ {
92
+ if (!isaTTY) return;
93
+
94
+ NSString *logMsg = logMessage->logMsg;
95
+ BOOL isFormatted = NO;
96
+
97
+ if (formatter)
98
+ {
99
+ logMsg = [formatter formatLogMessage:logMessage];
100
+ isFormatted = logMsg != logMessage->logMsg;
101
+ }
102
+
103
+ if (logMsg)
104
+ {
105
+ const char *msg = [logMsg UTF8String];
106
+ size_t msgLen = strlen(msg);
107
+
108
+ if (isFormatted)
109
+ {
110
+ struct iovec v[2];
111
+
112
+ v[0].iov_base = (char *)msg;
113
+ v[0].iov_len = msgLen;
114
+
115
+ v[1].iov_base = "\n";
116
+ v[1].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
117
+
118
+ writev(STDERR_FILENO, v, 2);
119
+ }
120
+ else
121
+ {
122
+ // The following is a highly optimized verion of file output to std err.
123
+
124
+ // ts = timestamp
125
+
126
+ NSString *tsNStr = [dateFormatter stringFromDate:(logMessage->timestamp)];
127
+
128
+ const char *tsCStr = [tsNStr UTF8String];
129
+ size_t tsLen = strlen(tsCStr);
130
+
131
+ // tid = thread id
132
+ //
133
+ // How many characters do we need for the thread id?
134
+ // logMessage->machThreadID is of type mach_port_t, which is an unsigned int.
135
+ //
136
+ // 1 hex char = 4 bits
137
+ // 8 hex chars for 32 bit, plus ending '\0' = 9
138
+
139
+ char tidCStr[9];
140
+ int tidLen = snprintf(tidCStr, 9, "%x", logMessage->machThreadID);
141
+
142
+ // Here is our format: "%s %s[%i:%s] %s", timestamp, appName, processID, threadID, logMsg
143
+
144
+ struct iovec v[10];
145
+
146
+ v[0].iov_base = (char *)tsCStr;
147
+ v[0].iov_len = tsLen;
148
+
149
+ v[1].iov_base = " ";
150
+ v[1].iov_len = 1;
151
+
152
+ v[2].iov_base = app;
153
+ v[2].iov_len = appLen;
154
+
155
+ v[3].iov_base = "[";
156
+ v[3].iov_len = 1;
157
+
158
+ v[4].iov_base = pid;
159
+ v[4].iov_len = pidLen;
160
+
161
+ v[5].iov_base = ":";
162
+ v[5].iov_len = 1;
163
+
164
+ v[6].iov_base = tidCStr;
165
+ v[6].iov_len = MIN((size_t)8, tidLen); // snprintf doesn't return what you might think
166
+
167
+ v[7].iov_base = "] ";
168
+ v[7].iov_len = 2;
169
+
170
+ v[8].iov_base = (char *)msg;
171
+ v[8].iov_len = msgLen;
172
+
173
+ v[9].iov_base = "\n";
174
+ v[9].iov_len = (msg[msgLen] == '\n') ? 0 : 1;
175
+
176
+ writev(STDERR_FILENO, v, 10);
177
+ }
178
+ }
179
+ }
180
+
181
+ - (NSString *)loggerName
182
+ {
183
+ return @"cocoa.lumberjack.ttyLogger";
184
+ }
185
+
186
+ @end
@@ -0,0 +1,37 @@
1
+ ### Lumberjack is Fast & Simple, yet Powerful & Flexible.
2
+
3
+ It is similar in concept to other popular logging frameworks such as log4j, yet is designed specifically for Objective-C, and takes advantage of features such as multi-threading, grand central dispatch (if available), lockless atomic operations, and the dynamic nature of the Objective-C runtime.
4
+
5
+ ### Lumberjack is Fast
6
+
7
+ In most cases it is an order of magnitude faster than NSLog.
8
+
9
+ ### Lumberjack is Simple
10
+
11
+ It takes as little as a single line of code to configure lumberjack when your application launches. Then simply replace your NSLog statements with DDLog statements and that's about it. (And the DDLog macros have the exact same format and syntax as NSLog, so it's super easy.)
12
+
13
+ ### Lumberjack is Powerful:
14
+
15
+ One log statement can be sent to multiple loggers, meaning you can log to a file and the console simultaneously. Want more? Create your own loggers (it's easy) and send your log statements over the network. Or to a database or distributed file system. The sky is the limit.
16
+
17
+ ### Lumberjack is Flexible:
18
+
19
+ Configure your logging however you want. Change log levels per file (perfect for debugging). Change log levels per logger (verbose console, but concise log file). Change log levels per xcode configuration (verbose debug, but concise release). Have your log statements compiled out of the release build. Customize the number of log levels for your application. Add your own fine-grained logging. Dynamically change log levels during runtime. Choose how & when you want your log files to be rolled. Upload your log files to a central server. Compress archived log files to save disk space...
20
+
21
+ <br/>
22
+ This framework is for you if:
23
+
24
+ - You're looking for a way to track down that impossible-to-reproduce bug that keeps popping up in the field.
25
+ - You're frustrated with the super short console log on the iPhone.
26
+ - You're looking to take your application to the next level in terms of support and stability.
27
+ - You're looking for an enterprise level logging solution for your application (Mac or iPhone).
28
+
29
+ <br/>
30
+ **[Get started using Lumberjack](https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted)**<br/>
31
+ **[Learn more about Lumberjack](https://github.com/robbiehanson/CocoaLumberjack/wiki)**<br/>
32
+
33
+ <br/>
34
+ Can't find the answer to your question in any of the [wiki](https://github.com/robbiehanson/CocoaLumberjack/wiki) articles? Try the **[mailing list](http://groups.google.com/group/cocoalumberjack)**.
35
+ <br/>
36
+ <br/>
37
+ Love the project? Wanna buy me a coffee? (or a beer :D) [![donation](http://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RW6R9U4ZWWZ8C)
@@ -0,0 +1,41 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <asl.h>
3
+
4
+ #import "DDLog.h"
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 for the Apple System Log facility.
17
+ *
18
+ * As described in the "Getting Started" page,
19
+ * the traditional NSLog() function directs it's output to two places:
20
+ *
21
+ * - Apple System Log
22
+ * - StdErr (if stderr is a TTY) so log statements show up in Xcode console
23
+ *
24
+ * To duplicate NSLog() functionality you can simply add this logger and a tty logger.
25
+ * However, if you instead choose to use file logging (for faster performance),
26
+ * you may choose to use a file logger and a tty logger.
27
+ **/
28
+
29
+ @interface DDASLLogger : DDAbstractLogger <DDLogger>
30
+ {
31
+ aslclient client;
32
+ }
33
+
34
+ + (DDASLLogger *)sharedInstance;
35
+
36
+ // Inherited from DDAbstractLogger
37
+
38
+ // - (id <DDLogFormatter>)logFormatter;
39
+ // - (void)setLogFormatter:(id <DDLogFormatter>)formatter;
40
+
41
+ @end
@@ -0,0 +1,102 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ #import "DDLog.h"
4
+
5
+ /**
6
+ * Welcome to Cocoa Lumberjack!
7
+ *
8
+ * The project page has a wealth of documentation if you have any questions.
9
+ * https://github.com/robbiehanson/CocoaLumberjack
10
+ *
11
+ * If you're new to the project you may wish to read the "Getting Started" wiki.
12
+ * https://github.com/robbiehanson/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