motion-logger 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/README.md +3 -1
  4. data/Rakefile +2 -4
  5. data/lib/logger/version.rb +1 -1
  6. data/motion-logger.gemspec +3 -3
  7. metadata +28 -51
  8. data/vendor/Podfile.lock +0 -5
  9. data/vendor/Pods/CocoaLumberjack/.gitignore +0 -24
  10. data/vendor/Pods/CocoaLumberjack/.hgignore +0 -6
  11. data/vendor/Pods/CocoaLumberjack/CocoaLumberjack.podspec +0 -18
  12. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +0 -18
  13. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +0 -41
  14. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +0 -99
  15. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +0 -102
  16. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +0 -618
  17. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +0 -334
  18. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +0 -1346
  19. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +0 -498
  20. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +0 -979
  21. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +0 -49
  22. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +0 -186
  23. data/vendor/Pods/CocoaLumberjack/README.markdown +0 -37
  24. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +0 -41
  25. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +0 -102
  26. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +0 -334
  27. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +0 -498
  28. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +0 -49
  29. data/vendor/Pods/Pods-Acknowledgements.markdown +0 -24
  30. data/vendor/Pods/Pods-Acknowledgements.plist +0 -54
  31. data/vendor/Pods/Pods-prefix.pch +0 -3
  32. data/vendor/Pods/Pods-resources.sh +0 -19
  33. data/vendor/Pods/Pods.bridgesupport +0 -462
  34. data/vendor/Pods/Pods.xcconfig +0 -4
  35. data/vendor/Pods/PodsDummy_Pods.m +0 -4
@@ -1,49 +0,0 @@
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
@@ -1,186 +0,0 @@
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
@@ -1,37 +0,0 @@
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)
@@ -1,41 +0,0 @@
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
@@ -1,102 +0,0 @@
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
@@ -1,334 +0,0 @@
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