Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pmbaty | 1 | #import "DDContextFilterLogFormatter.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/CocoaLumberjack/CocoaLumberjack |
||
9 | * |
||
10 | * If you're new to the project you may wish to read the "Getting Started" wiki. |
||
11 | * https://github.com/CocoaLumberjack/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 DDLoggingContextSet : 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 DDContextWhitelistFilterLogFormatter |
||
34 | { |
||
35 | DDLoggingContextSet *contextSet; |
||
36 | } |
||
37 | |||
38 | - (id)init |
||
39 | { |
||
40 | if ((self = [super init])) |
||
41 | { |
||
42 | contextSet = [[DDLoggingContextSet 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 DDContextBlacklistFilterLogFormatter |
||
83 | { |
||
84 | DDLoggingContextSet *contextSet; |
||
85 | } |
||
86 | |||
87 | - (id)init |
||
88 | { |
||
89 | if ((self = [super init])) |
||
90 | { |
||
91 | contextSet = [[DDLoggingContextSet 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 DDLoggingContextSet |
||
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 |