appjam 0.1.8.6 → 0.1.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appjam.rb +1 -1
- data/lib/appjam/generators/blank.rb +133 -0
- data/lib/appjam/generators/help.rb +5 -3
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/Default.png +0 -0
- data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/contents.tt +4 -0
- data/lib/appjam/version.rb +1 -1
- metadata +462 -326
- data/test/helper.rb +0 -132
- data/test/test_model_generator.rb +0 -28
- data/test/test_project_generator.rb +0 -38
@@ -0,0 +1,65 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import "DDLog.h"
|
3
|
+
|
4
|
+
@class ContextFilterLogFormatter;
|
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" page.
|
13
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
14
|
+
*
|
15
|
+
*
|
16
|
+
* This class provides a log formatter that filters log statements from a logging context not on the whitelist.
|
17
|
+
*
|
18
|
+
* A log formatter can be added to any logger to format and/or filter its output.
|
19
|
+
* You can learn more about log formatters here:
|
20
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomFormatters
|
21
|
+
*
|
22
|
+
* You can learn more about logging context's here:
|
23
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomContext
|
24
|
+
*
|
25
|
+
* But here's a quick overview / refresher:
|
26
|
+
*
|
27
|
+
* Every log statement has a logging context.
|
28
|
+
* These come from the underlying logging macros defined in DDLog.h.
|
29
|
+
* The default logging context is zero.
|
30
|
+
* You can define multiple logging context's for use in your application.
|
31
|
+
* For example, logically separate parts of your app each have a different logging context.
|
32
|
+
* Also 3rd party frameworks that make use of Lumberjack generally use their own dedicated logging context.
|
33
|
+
**/
|
34
|
+
@interface ContextWhitelistFilterLogFormatter : NSObject <DDLogFormatter>
|
35
|
+
|
36
|
+
- (id)init;
|
37
|
+
|
38
|
+
- (void)addToWhitelist:(int)loggingContext;
|
39
|
+
- (void)removeFromWhitelist:(int)loggingContext;
|
40
|
+
|
41
|
+
- (NSArray *)whitelist;
|
42
|
+
|
43
|
+
- (BOOL)isOnWhitelist:(int)loggingContext;
|
44
|
+
|
45
|
+
@end
|
46
|
+
|
47
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
+
#pragma mark -
|
49
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
+
|
51
|
+
/**
|
52
|
+
* This class provides a log formatter that filters log statements from a logging context on the blacklist.
|
53
|
+
**/
|
54
|
+
@interface ContextBlacklistFilterLogFormatter : NSObject <DDLogFormatter>
|
55
|
+
|
56
|
+
- (id)init;
|
57
|
+
|
58
|
+
- (void)addToBlacklist:(int)loggingContext;
|
59
|
+
- (void)removeFromBlacklist:(int)loggingContext;
|
60
|
+
|
61
|
+
- (NSArray *)blacklist;
|
62
|
+
|
63
|
+
- (BOOL)isOnBlacklist:(int)loggingContext;
|
64
|
+
|
65
|
+
@end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
#import "ContextFilterLogFormatter.h"
|
2
|
+
#import <libkern/OSAtomic.h>
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Welcome to Cocoa Lumberjack!
|
6
|
+
*
|
7
|
+
* The project page has a wealth of documentation if you have any questions.
|
8
|
+
* https://github.com/robbiehanson/CocoaLumberjack
|
9
|
+
*
|
10
|
+
* If you're new to the project you may wish to read the "Getting Started" wiki.
|
11
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
12
|
+
**/
|
13
|
+
|
14
|
+
#if ! __has_feature(objc_arc)
|
15
|
+
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
16
|
+
#endif
|
17
|
+
|
18
|
+
@interface LoggingContextSet : NSObject
|
19
|
+
|
20
|
+
- (void)addToSet:(int)loggingContext;
|
21
|
+
- (void)removeFromSet:(int)loggingContext;
|
22
|
+
|
23
|
+
- (NSArray *)currentSet;
|
24
|
+
|
25
|
+
- (BOOL)isInSet:(int)loggingContext;
|
26
|
+
|
27
|
+
@end
|
28
|
+
|
29
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
+
#pragma mark -
|
31
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
+
|
33
|
+
@implementation ContextWhitelistFilterLogFormatter
|
34
|
+
{
|
35
|
+
LoggingContextSet *contextSet;
|
36
|
+
}
|
37
|
+
|
38
|
+
- (id)init
|
39
|
+
{
|
40
|
+
if ((self = [super init]))
|
41
|
+
{
|
42
|
+
contextSet = [[LoggingContextSet alloc] init];
|
43
|
+
}
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
- (void)addToWhitelist:(int)loggingContext
|
49
|
+
{
|
50
|
+
[contextSet addToSet:loggingContext];
|
51
|
+
}
|
52
|
+
|
53
|
+
- (void)removeFromWhitelist:(int)loggingContext
|
54
|
+
{
|
55
|
+
[contextSet removeFromSet:loggingContext];
|
56
|
+
}
|
57
|
+
|
58
|
+
- (NSArray *)whitelist
|
59
|
+
{
|
60
|
+
return [contextSet currentSet];
|
61
|
+
}
|
62
|
+
|
63
|
+
- (BOOL)isOnWhitelist:(int)loggingContext
|
64
|
+
{
|
65
|
+
return [contextSet isInSet:loggingContext];
|
66
|
+
}
|
67
|
+
|
68
|
+
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
|
69
|
+
{
|
70
|
+
if ([self isOnWhitelist:logMessage->logContext])
|
71
|
+
return logMessage->logMsg;
|
72
|
+
else
|
73
|
+
return nil;
|
74
|
+
}
|
75
|
+
|
76
|
+
@end
|
77
|
+
|
78
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
+
#pragma mark -
|
80
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
+
|
82
|
+
@implementation ContextBlacklistFilterLogFormatter
|
83
|
+
{
|
84
|
+
LoggingContextSet *contextSet;
|
85
|
+
}
|
86
|
+
|
87
|
+
- (id)init
|
88
|
+
{
|
89
|
+
if ((self = [super init]))
|
90
|
+
{
|
91
|
+
contextSet = [[LoggingContextSet alloc] init];
|
92
|
+
}
|
93
|
+
return self;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
- (void)addToBlacklist:(int)loggingContext
|
98
|
+
{
|
99
|
+
[contextSet addToSet:loggingContext];
|
100
|
+
}
|
101
|
+
|
102
|
+
- (void)removeFromBlacklist:(int)loggingContext
|
103
|
+
{
|
104
|
+
[contextSet removeFromSet:loggingContext];
|
105
|
+
}
|
106
|
+
|
107
|
+
- (NSArray *)blacklist
|
108
|
+
{
|
109
|
+
return [contextSet currentSet];
|
110
|
+
}
|
111
|
+
|
112
|
+
- (BOOL)isOnBlacklist:(int)loggingContext
|
113
|
+
{
|
114
|
+
return [contextSet isInSet:loggingContext];
|
115
|
+
}
|
116
|
+
|
117
|
+
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
|
118
|
+
{
|
119
|
+
if ([self isOnBlacklist:logMessage->logContext])
|
120
|
+
return nil;
|
121
|
+
else
|
122
|
+
return logMessage->logMsg;
|
123
|
+
}
|
124
|
+
|
125
|
+
@end
|
126
|
+
|
127
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
128
|
+
#pragma mark -
|
129
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
+
|
131
|
+
@implementation LoggingContextSet
|
132
|
+
{
|
133
|
+
OSSpinLock lock;
|
134
|
+
NSMutableSet *set;
|
135
|
+
}
|
136
|
+
|
137
|
+
- (id)init
|
138
|
+
{
|
139
|
+
if ((self = [super init]))
|
140
|
+
{
|
141
|
+
set = [[NSMutableSet alloc] init];
|
142
|
+
}
|
143
|
+
return self;
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
- (void)addToSet:(int)loggingContext
|
148
|
+
{
|
149
|
+
OSSpinLockLock(&lock);
|
150
|
+
{
|
151
|
+
[set addObject:@(loggingContext)];
|
152
|
+
}
|
153
|
+
OSSpinLockUnlock(&lock);
|
154
|
+
}
|
155
|
+
|
156
|
+
- (void)removeFromSet:(int)loggingContext
|
157
|
+
{
|
158
|
+
OSSpinLockLock(&lock);
|
159
|
+
{
|
160
|
+
[set removeObject:@(loggingContext)];
|
161
|
+
}
|
162
|
+
OSSpinLockUnlock(&lock);
|
163
|
+
}
|
164
|
+
|
165
|
+
- (NSArray *)currentSet
|
166
|
+
{
|
167
|
+
NSArray *result = nil;
|
168
|
+
|
169
|
+
OSSpinLockLock(&lock);
|
170
|
+
{
|
171
|
+
result = [set allObjects];
|
172
|
+
}
|
173
|
+
OSSpinLockUnlock(&lock);
|
174
|
+
|
175
|
+
return result;
|
176
|
+
}
|
177
|
+
|
178
|
+
- (BOOL)isInSet:(int)loggingContext
|
179
|
+
{
|
180
|
+
BOOL result = NO;
|
181
|
+
|
182
|
+
OSSpinLockLock(&lock);
|
183
|
+
{
|
184
|
+
result = [set containsObject:@(loggingContext)];
|
185
|
+
}
|
186
|
+
OSSpinLockUnlock(&lock);
|
187
|
+
|
188
|
+
return result;
|
189
|
+
}
|
190
|
+
|
191
|
+
@end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import <libkern/OSAtomic.h>
|
3
|
+
#import "DDLog.h"
|
4
|
+
|
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" page.
|
13
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
14
|
+
*
|
15
|
+
*
|
16
|
+
* This class provides a log formatter that prints the dispatch_queue label instead of the mach_thread_id.
|
17
|
+
*
|
18
|
+
* A log formatter can be added to any logger to format and/or filter its output.
|
19
|
+
* You can learn more about log formatters here:
|
20
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomFormatters
|
21
|
+
*
|
22
|
+
* A typical NSLog (or DDTTYLogger) prints detailed info as [<process_id>:<thread_id>].
|
23
|
+
* For example:
|
24
|
+
*
|
25
|
+
* 2011-10-17 20:21:45.435 AppName[19928:5207] Your log message here
|
26
|
+
*
|
27
|
+
* Where:
|
28
|
+
* - 19928 = process id
|
29
|
+
* - 5207 = thread id (mach_thread_id printed in hex)
|
30
|
+
*
|
31
|
+
* When using grand central dispatch (GCD), this information is less useful.
|
32
|
+
* This is because a single serial dispatch queue may be run on any thread from an internally managed thread pool.
|
33
|
+
* For example:
|
34
|
+
*
|
35
|
+
* 2011-10-17 20:32:31.111 AppName[19954:4d07] Message from my_serial_dispatch_queue
|
36
|
+
* 2011-10-17 20:32:31.112 AppName[19954:5207] Message from my_serial_dispatch_queue
|
37
|
+
* 2011-10-17 20:32:31.113 AppName[19954:2c55] Message from my_serial_dispatch_queue
|
38
|
+
*
|
39
|
+
* This formatter allows you to replace the standard [box:info] with the dispatch_queue name.
|
40
|
+
* For example:
|
41
|
+
*
|
42
|
+
* 2011-10-17 20:32:31.111 AppName[img-scaling] Message from my_serial_dispatch_queue
|
43
|
+
* 2011-10-17 20:32:31.112 AppName[img-scaling] Message from my_serial_dispatch_queue
|
44
|
+
* 2011-10-17 20:32:31.113 AppName[img-scaling] Message from my_serial_dispatch_queue
|
45
|
+
*
|
46
|
+
* If the dispatch_queue doesn't have a set name, then it falls back to the thread name.
|
47
|
+
* If the current thread doesn't have a set name, then it falls back to the mach_thread_id in hex (like normal).
|
48
|
+
*
|
49
|
+
* Note: If manually creating your own background threads (via NSThread/alloc/init or NSThread/detachNeThread),
|
50
|
+
* you can use [[NSThread currentThread] setName:(NSString *)].
|
51
|
+
**/
|
52
|
+
@interface DispatchQueueLogFormatter : NSObject <DDLogFormatter> {
|
53
|
+
@protected
|
54
|
+
|
55
|
+
NSString *dateFormatString;
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Standard init method.
|
60
|
+
* Configure using properties as desired.
|
61
|
+
**/
|
62
|
+
- (id)init;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* The minQueueLength restricts the minimum size of the [detail box].
|
66
|
+
* If the minQueueLength is set to 0, there is no restriction.
|
67
|
+
*
|
68
|
+
* For example, say a dispatch_queue has a label of "diskIO":
|
69
|
+
*
|
70
|
+
* If the minQueueLength is 0: [diskIO]
|
71
|
+
* If the minQueueLength is 4: [diskIO]
|
72
|
+
* If the minQueueLength is 5: [diskIO]
|
73
|
+
* If the minQueueLength is 6: [diskIO]
|
74
|
+
* If the minQueueLength is 7: [diskIO ]
|
75
|
+
* If the minQueueLength is 8: [diskIO ]
|
76
|
+
*
|
77
|
+
* The default minQueueLength is 0 (no minimum, so [detail box] won't be padded).
|
78
|
+
*
|
79
|
+
* If you want every [detail box] to have the exact same width,
|
80
|
+
* set both minQueueLength and maxQueueLength to the same value.
|
81
|
+
**/
|
82
|
+
@property (assign) NSUInteger minQueueLength;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* The maxQueueLength restricts the number of characters that will be inside the [detail box].
|
86
|
+
* If the maxQueueLength is 0, there is no restriction.
|
87
|
+
*
|
88
|
+
* For example, say a dispatch_queue has a label of "diskIO":
|
89
|
+
*
|
90
|
+
* If the maxQueueLength is 0: [diskIO]
|
91
|
+
* If the maxQueueLength is 4: [disk]
|
92
|
+
* If the maxQueueLength is 5: [diskI]
|
93
|
+
* If the maxQueueLength is 6: [diskIO]
|
94
|
+
* If the maxQueueLength is 7: [diskIO]
|
95
|
+
* If the maxQueueLength is 8: [diskIO]
|
96
|
+
*
|
97
|
+
* The default maxQueueLength is 0 (no maximum, so [detail box] won't be truncated).
|
98
|
+
*
|
99
|
+
* If you want every [detail box] to have the exact same width,
|
100
|
+
* set both minQueueLength and maxQueueLength to the same value.
|
101
|
+
**/
|
102
|
+
@property (assign) NSUInteger maxQueueLength;
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Sometimes queue labels have long names like "com.apple.main-queue",
|
106
|
+
* but you'd prefer something shorter like simply "main".
|
107
|
+
*
|
108
|
+
* This method allows you to set such preferred replacements.
|
109
|
+
* The above example is set by default.
|
110
|
+
*
|
111
|
+
* To remove/undo a previous replacement, invoke this method with nil for the 'shortLabel' parameter.
|
112
|
+
**/
|
113
|
+
- (NSString *)replacementStringForQueueLabel:(NSString *)longLabel;
|
114
|
+
- (void)setReplacementString:(NSString *)shortLabel forQueueLabel:(NSString *)longLabel;
|
115
|
+
|
116
|
+
@end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
#import "DispatchQueueLogFormatter.h"
|
2
|
+
#import <libkern/OSAtomic.h>
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Welcome to Cocoa Lumberjack!
|
6
|
+
*
|
7
|
+
* The project page has a wealth of documentation if you have any questions.
|
8
|
+
* https://github.com/robbiehanson/CocoaLumberjack
|
9
|
+
*
|
10
|
+
* If you're new to the project you may wish to read the "Getting Started" wiki.
|
11
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
12
|
+
**/
|
13
|
+
|
14
|
+
#if ! __has_feature(objc_arc)
|
15
|
+
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
16
|
+
#endif
|
17
|
+
|
18
|
+
|
19
|
+
@implementation DispatchQueueLogFormatter
|
20
|
+
{
|
21
|
+
int32_t atomicLoggerCount;
|
22
|
+
NSDateFormatter *threadUnsafeDateFormatter; // Use [self stringFromDate]
|
23
|
+
|
24
|
+
OSSpinLock lock;
|
25
|
+
|
26
|
+
NSUInteger _minQueueLength; // _prefix == Only access via atomic property
|
27
|
+
NSUInteger _maxQueueLength; // _prefix == Only access via atomic property
|
28
|
+
NSMutableDictionary *_replacements; // _prefix == Only access from within spinlock
|
29
|
+
}
|
30
|
+
|
31
|
+
- (id)init
|
32
|
+
{
|
33
|
+
if ((self = [super init]))
|
34
|
+
{
|
35
|
+
dateFormatString = @"yyyy-MM-dd HH:mm:ss:SSS";
|
36
|
+
|
37
|
+
atomicLoggerCount = 0;
|
38
|
+
threadUnsafeDateFormatter = nil;
|
39
|
+
|
40
|
+
_minQueueLength = 0;
|
41
|
+
_maxQueueLength = 0;
|
42
|
+
_replacements = [[NSMutableDictionary alloc] init];
|
43
|
+
|
44
|
+
// Set default replacements:
|
45
|
+
|
46
|
+
[_replacements setObject:@"main" forKey:@"com.apple.main-thread"];
|
47
|
+
}
|
48
|
+
return self;
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
+
#pragma mark Configuration
|
54
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
+
|
56
|
+
@synthesize minQueueLength = _minQueueLength;
|
57
|
+
@synthesize maxQueueLength = _maxQueueLength;
|
58
|
+
|
59
|
+
- (NSString *)replacementStringForQueueLabel:(NSString *)longLabel
|
60
|
+
{
|
61
|
+
NSString *result = nil;
|
62
|
+
|
63
|
+
OSSpinLockLock(&lock);
|
64
|
+
{
|
65
|
+
result = [_replacements objectForKey:longLabel];
|
66
|
+
}
|
67
|
+
OSSpinLockUnlock(&lock);
|
68
|
+
|
69
|
+
return result;
|
70
|
+
}
|
71
|
+
|
72
|
+
- (void)setReplacementString:(NSString *)shortLabel forQueueLabel:(NSString *)longLabel
|
73
|
+
{
|
74
|
+
OSSpinLockLock(&lock);
|
75
|
+
{
|
76
|
+
if (shortLabel)
|
77
|
+
[_replacements setObject:shortLabel forKey:longLabel];
|
78
|
+
else
|
79
|
+
[_replacements removeObjectForKey:longLabel];
|
80
|
+
}
|
81
|
+
OSSpinLockUnlock(&lock);
|
82
|
+
}
|
83
|
+
|
84
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
+
#pragma mark DDLogFormatter
|
86
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
+
|
88
|
+
- (NSString *)stringFromDate:(NSDate *)date
|
89
|
+
{
|
90
|
+
int32_t loggerCount = OSAtomicAdd32(0, &atomicLoggerCount);
|
91
|
+
|
92
|
+
if (loggerCount <= 1)
|
93
|
+
{
|
94
|
+
// Single-threaded mode.
|
95
|
+
|
96
|
+
if (threadUnsafeDateFormatter == nil)
|
97
|
+
{
|
98
|
+
threadUnsafeDateFormatter = [[NSDateFormatter alloc] init];
|
99
|
+
[threadUnsafeDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
|
100
|
+
[threadUnsafeDateFormatter setDateFormat:dateFormatString];
|
101
|
+
}
|
102
|
+
|
103
|
+
return [threadUnsafeDateFormatter stringFromDate:date];
|
104
|
+
}
|
105
|
+
else
|
106
|
+
{
|
107
|
+
// Multi-threaded mode.
|
108
|
+
// NSDateFormatter is NOT thread-safe.
|
109
|
+
|
110
|
+
NSString *key = @"DispatchQueueLogFormatter_NSDateFormatter";
|
111
|
+
|
112
|
+
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
113
|
+
NSDateFormatter *dateFormatter = [threadDictionary objectForKey:key];
|
114
|
+
|
115
|
+
if (dateFormatter == nil)
|
116
|
+
{
|
117
|
+
dateFormatter = [[NSDateFormatter alloc] init];
|
118
|
+
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
|
119
|
+
[dateFormatter setDateFormat:dateFormatString];
|
120
|
+
|
121
|
+
[threadDictionary setObject:dateFormatter forKey:key];
|
122
|
+
}
|
123
|
+
|
124
|
+
return [dateFormatter stringFromDate:date];
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
- (NSString *)queueThreadLabelForLogMessage:(DDLogMessage *)logMessage
|
129
|
+
{
|
130
|
+
// As per the DDLogFormatter contract, this method is always invoked on the same thread/dispatch_queue
|
131
|
+
|
132
|
+
NSUInteger minQueueLength = self.minQueueLength;
|
133
|
+
NSUInteger maxQueueLength = self.maxQueueLength;
|
134
|
+
|
135
|
+
// Get the name of the queue, thread, or machID (whichever we are to use).
|
136
|
+
|
137
|
+
NSString *queueThreadLabel = nil;
|
138
|
+
|
139
|
+
BOOL useQueueLabel = YES;
|
140
|
+
BOOL useThreadName = NO;
|
141
|
+
|
142
|
+
if (logMessage->queueLabel)
|
143
|
+
{
|
144
|
+
// If you manually create a thread, it's dispatch_queue will have one of the thread names below.
|
145
|
+
// Since all such threads have the same name, we'd prefer to use the threadName or the machThreadID.
|
146
|
+
|
147
|
+
char *names[] = { "com.apple.root.low-priority",
|
148
|
+
"com.apple.root.default-priority",
|
149
|
+
"com.apple.root.high-priority",
|
150
|
+
"com.apple.root.low-overcommit-priority",
|
151
|
+
"com.apple.root.default-overcommit-priority",
|
152
|
+
"com.apple.root.high-overcommit-priority" };
|
153
|
+
|
154
|
+
int length = sizeof(names) / sizeof(char *);
|
155
|
+
|
156
|
+
int i;
|
157
|
+
for (i = 0; i < length; i++)
|
158
|
+
{
|
159
|
+
if (strcmp(logMessage->queueLabel, names[i]) == 0)
|
160
|
+
{
|
161
|
+
useQueueLabel = NO;
|
162
|
+
useThreadName = [logMessage->threadName length] > 0;
|
163
|
+
break;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
else
|
168
|
+
{
|
169
|
+
useQueueLabel = NO;
|
170
|
+
useThreadName = [logMessage->threadName length] > 0;
|
171
|
+
}
|
172
|
+
|
173
|
+
if (useQueueLabel || useThreadName)
|
174
|
+
{
|
175
|
+
NSString *fullLabel;
|
176
|
+
NSString *abrvLabel;
|
177
|
+
|
178
|
+
if (useQueueLabel)
|
179
|
+
fullLabel = @(logMessage->queueLabel);
|
180
|
+
else
|
181
|
+
fullLabel = logMessage->threadName;
|
182
|
+
|
183
|
+
OSSpinLockLock(&lock);
|
184
|
+
{
|
185
|
+
abrvLabel = [_replacements objectForKey:fullLabel];
|
186
|
+
}
|
187
|
+
OSSpinLockUnlock(&lock);
|
188
|
+
|
189
|
+
if (abrvLabel)
|
190
|
+
queueThreadLabel = abrvLabel;
|
191
|
+
else
|
192
|
+
queueThreadLabel = fullLabel;
|
193
|
+
}
|
194
|
+
else
|
195
|
+
{
|
196
|
+
queueThreadLabel = [NSString stringWithFormat:@"%x", logMessage->machThreadID];
|
197
|
+
}
|
198
|
+
|
199
|
+
// Now use the thread label in the output
|
200
|
+
|
201
|
+
NSUInteger labelLength = [queueThreadLabel length];
|
202
|
+
|
203
|
+
// labelLength > maxQueueLength : truncate
|
204
|
+
// labelLength < minQueueLength : padding
|
205
|
+
// : exact
|
206
|
+
|
207
|
+
if ((maxQueueLength > 0) && (labelLength > maxQueueLength))
|
208
|
+
{
|
209
|
+
// Truncate
|
210
|
+
|
211
|
+
return [queueThreadLabel substringToIndex:maxQueueLength];
|
212
|
+
}
|
213
|
+
else if (labelLength < minQueueLength)
|
214
|
+
{
|
215
|
+
// Padding
|
216
|
+
|
217
|
+
NSUInteger numSpaces = minQueueLength - labelLength;
|
218
|
+
|
219
|
+
char spaces[numSpaces + 1];
|
220
|
+
memset(spaces, ' ', numSpaces);
|
221
|
+
spaces[numSpaces] = '\0';
|
222
|
+
|
223
|
+
return [NSString stringWithFormat:@"%@%s", queueThreadLabel, spaces];
|
224
|
+
}
|
225
|
+
else
|
226
|
+
{
|
227
|
+
// Exact
|
228
|
+
|
229
|
+
return queueThreadLabel;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
|
234
|
+
{
|
235
|
+
NSString *timestamp = [self stringFromDate:(logMessage->timestamp)];
|
236
|
+
NSString *queueThreadLabel = [self queueThreadLabelForLogMessage:logMessage];
|
237
|
+
|
238
|
+
return [NSString stringWithFormat:@"%@ [%@] %@", timestamp, queueThreadLabel, logMessage->logMsg];
|
239
|
+
}
|
240
|
+
|
241
|
+
- (void)didAddToLogger:(id <DDLogger>)logger
|
242
|
+
{
|
243
|
+
OSAtomicIncrement32(&atomicLoggerCount);
|
244
|
+
}
|
245
|
+
|
246
|
+
- (void)willRemoveFromLogger:(id <DDLogger>)logger
|
247
|
+
{
|
248
|
+
OSAtomicDecrement32(&atomicLoggerCount);
|
249
|
+
}
|
250
|
+
|
251
|
+
@end
|