Skip to content

Commit

Permalink
NR-227297: logErrorObject impl, NR-227300: logAttributes impl
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Mar 8, 2024
1 parent 0f0f415 commit 04dd99e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Agent/Public/NewRelic.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ extern "C" {
// Dict should contain at minimum => String: "message" and String: "logLevel" where logLevel is one of NONE < ERROR < WARN < INFO < DEBUG < VERBOSE
+ (void) logAll:(NSDictionary* __nonnull) dict;

+ (void) logAttributes:(NSDictionary* __nonnull) dict;

+ (void) logErrorObject:(NSError* __nonnull) error;

#pragma mark - Configuring the New Relic SDK

/*!
Expand Down
15 changes: 15 additions & 0 deletions Agent/Public/NewRelic.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ + (void) logAll:(NSDictionary* __nonnull) dict {
[self log:message level:levels];
}

+ (void) logAttributes:(NSDictionary* __nonnull) dict {
NSString* message = [dict objectForKey:@"message"];
NSString* level = [dict objectForKey:@"logLevel"];

NRLogLevels levels = [NRLogger stringToLevel: level];

[self log:message level:levels];
}

+ (void) logErrorObject:(NSError* __nonnull) error {
NSString * errorDesc = error.localizedDescription;

[self logError:[NSString stringWithFormat:@"Error encountered: %@", errorDesc]];
}

+ (void) crashNow:(NSString*)message
{
// If Agent is shutdown we shouldn't respond.
Expand Down
1 change: 0 additions & 1 deletion Agent/Public/NewRelicFeatureFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
*/



typedef NS_OPTIONS(unsigned long long, NRMAFeatureFlags){
NRFeatureFlag_InteractionTracing = 1 << 1,
NRFeatureFlag_SwiftInteractionTracing = 1 << 2, // Disabled by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class NRTestAppUITests: XCTestCase {
let dynamicStubs = HTTPDynamicStubs()

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

let app = XCUIApplication()
dynamicStubs.setUp()
Expand Down
14 changes: 14 additions & 0 deletions Tests/Unit-Tests/NewRelicAgentTests/API-Tests/NewRelicTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,20 @@ - (void) testLogging {
XCTAssertNoThrow([NewRelic logWarning:@"Wazzzup?"]);
XCTAssertNoThrow([NewRelic logAudit:@"Wazzzup?"]);

NSDictionary *dict = @{@"logLevel": @"WARN",
@"message": @"This is a test message for the New Relic logging system."};

XCTAssertNoThrow([NewRelic logAll:dict]);

NSError* error = [NSError errorWithDomain:@"NSErrorUnknownDomain" code:NSURLErrorUnknown userInfo:@{}];

XCTAssertNoThrow([NewRelic logErrorObject:error]);

NSDictionary *dict2 = @{@"logLevel": @"WARN",
@"message": @"This is a test message for the New Relic logging system."};

XCTAssertNoThrow([NewRelic logAttributes:dict2]);

}

- (void) testRecordHandledExceptionsNewEventSystem {
Expand Down

0 comments on commit 04dd99e

Please sign in to comment.