@@ -167,8 +167,100 @@ - (void) testNRLogger {
167
167
168
168
- (void ) testRemoteLogLevels {
169
169
170
- // Set the remote log level to warning.
171
- [NRLogger setRemoteLogLevel: NRLogLevelWarning];
170
+ [NRLogger setLogLevels: NRLogLevelInfo];
171
+
172
+ // Set the remote log level to Debug.
173
+ [NRLogger setRemoteLogLevel: NRLogLevelDebug];
174
+
175
+ XCTestExpectation *delayExpectation1 = [self expectationWithDescription: @" Waiting for Log Queue" ];
176
+
177
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(2 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
178
+ [delayExpectation1 fulfill ];
179
+ });
180
+
181
+ [self waitForExpectationsWithTimeout: 5 handler: ^(NSError * _Nullable error) {
182
+ if (error) {
183
+ XCTFail (@" Timeout error" );
184
+ }
185
+ }];
186
+
187
+ // Seven messages should reach the remote log file for upload.
188
+
189
+ [NewRelic logInfo: @" Info Log..." ];
190
+ [NewRelic logError: @" Error Log..." ];
191
+ [NewRelic logVerbose: @" Verbose Log..." ];
192
+ [NewRelic logWarning: @" Warning Log..." ];
193
+ [NewRelic logAudit: @" Audit Log..." ];
194
+ [NewRelic logDebug: @" Debug Log..." ];
195
+ [NewRelic logAttributes: @{
196
+ @" logLevel" : @" WARN" ,
197
+ @" message" : @" This is a test message for the New Relic logging system." ,
198
+ @" additionalAttribute1" : @" attribute1" ,
199
+ @" additionalAttribute2" : @" attribute2"
200
+ }];
201
+
202
+ XCTestExpectation *delayExpectation2 = [self expectationWithDescription: @" Waiting for Log Queue" ];
203
+
204
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(2 * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
205
+ [delayExpectation2 fulfill ];
206
+ });
207
+
208
+ [self waitForExpectationsWithTimeout: 5 handler: ^(NSError * _Nullable error) {
209
+ if (error) {
210
+ XCTFail (@" Timeout error" );
211
+ }
212
+ }];
213
+
214
+ NSError * error;
215
+ NSData * logData = [NRLogger logFileData: &error];
216
+ if (error){
217
+ NSLog (@" %@ " , error.localizedDescription );
218
+ }
219
+ NSString * logMessagesJson = [NSString stringWithFormat: @" [ %@ ]" , [[NSString alloc ] initWithData: logData encoding: NSUTF8StringEncoding]];
220
+ NSData * formattedData = [logMessagesJson dataUsingEncoding: NSUTF8StringEncoding];
221
+ NSArray * decode = [NSJSONSerialization JSONObjectWithData: formattedData
222
+ options: 0
223
+ error: nil ];
224
+ NSLog (@" decode=%@ " , decode);
225
+
226
+ NSArray * expectedValues = @[
227
+ @{@" message" : @" Info Log..." },
228
+ @{@" message" : @" Error Log..." },
229
+ @{@" message" : @" Verbose Log..." },
230
+ @{@" message" : @" Warning Log..." },
231
+ @{@" message" : @" Audit Log..." },
232
+ @{@" message" : @" Debug Log..." },
233
+ @{@" message" : @" This is a test message for the New Relic logging system." },
234
+ ];
235
+ // check for existence of 6 logs.
236
+ int foundCount = 0 ;
237
+ // For each expected message.
238
+ for (NSDictionary *dict in expectedValues) {
239
+ // Iterate through the collected message logs.
240
+ for (NSDictionary *dict2 in decode) {
241
+ //
242
+ NSString * currentMessage = [dict objectForKey: @" message" ];
243
+ if ([[dict2 objectForKey: @" message" ] isEqualToString: currentMessage]) {
244
+ foundCount += 1 ;
245
+ XCTAssertTrue ([[dict2 objectForKey: @" entity.guid" ] isEqualToString: @" Entity-Guid-XXXX" ],@" entity.guid set incorrectly" );
246
+ }
247
+ // Verify added attributes with logAttributes.
248
+ if ([[dict2 objectForKey: @" message" ] isEqualToString: @" This is a test message for the New Relic logging system." ]) {
249
+ XCTAssertTrue ([[dict2 objectForKey: @" additionalAttribute1" ] isEqualToString: @" attribute1" ],@" additionalAttribute1 set incorrectly" );
250
+ XCTAssertTrue ([[dict2 objectForKey: @" additionalAttribute2" ] isEqualToString: @" attribute2" ],@" additionalAttribute2 set incorrectly" );
251
+ }
252
+ }
253
+ }
254
+
255
+ XCTAssertEqual (foundCount, 7 , @" Seven remote messages should be found." );
256
+ }
257
+
258
+ - (void ) testLocalLogLevels {
259
+
260
+ // Set the local log level to Debug
261
+ [NRLogger setLogLevels: NRLogLevelDebug];
262
+ // Set the remote log level to Info.
263
+ [NRLogger setRemoteLogLevel: NRLogLevelInfo];
172
264
173
265
XCTestExpectation *delayExpectation1 = [self expectationWithDescription: @" Waiting for Log Queue" ];
174
266
@@ -182,7 +274,7 @@ - (void) testRemoteLogLevels {
182
274
}
183
275
}];
184
276
185
- // Three messages should reach the remote log file for upload.
277
+ // Seven messages should reach the remote log file for upload.
186
278
187
279
[NewRelic logInfo: @" Info Log..." ];
188
280
[NewRelic logError: @" Error Log..." ];
@@ -250,7 +342,7 @@ - (void) testRemoteLogLevels {
250
342
}
251
343
}
252
344
253
- XCTAssertEqual (foundCount, 3 , @" Three remote messages should be found." );
345
+ XCTAssertEqual (foundCount, 4 , @" Four remote messages should be found." );
254
346
}
255
347
256
348
@end
0 commit comments