Skip to content

Commit 04dd99e

Browse files
NR-227297: logErrorObject impl, NR-227300: logAttributes impl
1 parent 0f0f415 commit 04dd99e

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

Agent/Public/NewRelic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extern "C" {
6969
// Dict should contain at minimum => String: "message" and String: "logLevel" where logLevel is one of NONE < ERROR < WARN < INFO < DEBUG < VERBOSE
7070
+ (void) logAll:(NSDictionary* __nonnull) dict;
7171

72+
+ (void) logAttributes:(NSDictionary* __nonnull) dict;
73+
74+
+ (void) logErrorObject:(NSError* __nonnull) error;
75+
7276
#pragma mark - Configuring the New Relic SDK
7377

7478
/*!

Agent/Public/NewRelic.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ + (void) logAll:(NSDictionary* __nonnull) dict {
9494
[self log:message level:levels];
9595
}
9696

97+
+ (void) logAttributes:(NSDictionary* __nonnull) dict {
98+
NSString* message = [dict objectForKey:@"message"];
99+
NSString* level = [dict objectForKey:@"logLevel"];
100+
101+
NRLogLevels levels = [NRLogger stringToLevel: level];
102+
103+
[self log:message level:levels];
104+
}
105+
106+
+ (void) logErrorObject:(NSError* __nonnull) error {
107+
NSString * errorDesc = error.localizedDescription;
108+
109+
[self logError:[NSString stringWithFormat:@"Error encountered: %@", errorDesc]];
110+
}
111+
97112
+ (void) crashNow:(NSString*)message
98113
{
99114
// If Agent is shutdown we shouldn't respond.

Agent/Public/NewRelicFeatureFlags.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
*/
8080

8181

82-
8382
typedef NS_OPTIONS(unsigned long long, NRMAFeatureFlags){
8483
NRFeatureFlag_InteractionTracing = 1 << 1,
8584
NRFeatureFlag_SwiftInteractionTracing = 1 << 2, // Disabled by default

Test Harness/NRTestApp/NRTestAppUITests/NRTestAppUITests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class NRTestAppUITests: XCTestCase {
1616
let dynamicStubs = HTTPDynamicStubs()
1717

1818
let vendorId = "myDeviceId"
19-
let harvestConnector = "[[\"NRTestApp\",\"4.7\",\"com.newrelic.NRApp.bitcode\"],[\"iOS\",\"17.0\",\"arm64\",\"iOSAgent\",\"DEV\",\"\(vendorId)\",\"\",\"\",\"Apple Inc.\",{\"platform\":\"Native\",\"platformVersion\":\"DEV\"}]]"
19+
let harvestConnector = "[[\"NRTestApp\",\"4.7\",\"com.newrelic.NRApp.bitcode\"],[\"iOS\",\"17.0.1\",\"arm64\",\"iOSAgent\",\"DEV\",\"\(vendorId)\",\"\",\"\",\"Apple Inc.\",{\"platform\":\"Native\",\"platformVersion\":\"DEV\"}]]"
2020

2121
let app = XCUIApplication()
2222
dynamicStubs.setUp()

Tests/Unit-Tests/NewRelicAgentTests/API-Tests/NewRelicTests.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,20 @@ - (void) testLogging {
462462
XCTAssertNoThrow([NewRelic logWarning:@"Wazzzup?"]);
463463
XCTAssertNoThrow([NewRelic logAudit:@"Wazzzup?"]);
464464

465+
NSDictionary *dict = @{@"logLevel": @"WARN",
466+
@"message": @"This is a test message for the New Relic logging system."};
467+
468+
XCTAssertNoThrow([NewRelic logAll:dict]);
469+
470+
NSError* error = [NSError errorWithDomain:@"NSErrorUnknownDomain" code:NSURLErrorUnknown userInfo:@{}];
471+
472+
XCTAssertNoThrow([NewRelic logErrorObject:error]);
473+
474+
NSDictionary *dict2 = @{@"logLevel": @"WARN",
475+
@"message": @"This is a test message for the New Relic logging system."};
476+
477+
XCTAssertNoThrow([NewRelic logAttributes:dict2]);
478+
465479
}
466480

467481
- (void) testRecordHandledExceptionsNewEventSystem {

0 commit comments

Comments
 (0)