Skip to content

Commit

Permalink
feat: log forwarding functionality
Browse files Browse the repository at this point in the history
Add static Methods for log messages and feature flag for log reporting enabled
  • Loading branch information
ndesai-newrelic committed Jul 24, 2024
1 parent 2dfd54d commit 6fda3c3
Show file tree
Hide file tree
Showing 8 changed files with 634 additions and 462 deletions.
9 changes: 8 additions & 1 deletion __mocks__/nrm-modular-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ export default {
shutdown:jest.fn(),
addHTTPHeadersTrackingFor:jest.fn(),
setMaxOfflineStorageSize: jest.fn(),

log: jest.fn(),
logInfo: jest.fn(),
logAttributes: jest.fn(),
logAll: jest.fn(),
logVerbose: jest.fn(),
logDebug: jest.fn(),
logError: jest.fn(),
logWarning: jest.fn(),

isAgentStarted: (name, callback) => {
callback(true);
Expand Down
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ android {
repositories {
mavenCentral()
google()
maven { url "https://oss.sonatype.org/content/repositories/comnewrelic-2914"}

}

dependencies {
Expand Down
11 changes: 11 additions & 0 deletions android/src/main/java/com/NewRelic/NRMModularAgentModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.newrelic.agent.android.NewRelic;
import com.newrelic.agent.android.ApplicationFramework;
import com.newrelic.agent.android.logging.AgentLog;
import com.newrelic.agent.android.logging.LogLevel;
import com.newrelic.agent.android.logging.LogReporting;
import com.newrelic.agent.android.stats.StatsEngine;
import com.newrelic.agent.android.metric.MetricUnit;
import com.newrelic.agent.android.util.NetworkFailure;
Expand Down Expand Up @@ -110,6 +112,13 @@ public void startAgent(String appKey, String agentVersion, String reactNativeVer
NewRelic.disableFeature(FeatureFlag.NativeReporting);
}

if ((Boolean) agentConfig.get("logReportingEnabled")) {
NewRelic.enableFeature(FeatureFlag.LogReporting);
} else {
NewRelic.disableFeature(FeatureFlag.LogReporting);
}


Map<String, Integer> strToLogLevel = new HashMap<>();
strToLogLevel.put("ERROR", AgentLog.ERROR);
strToLogLevel.put("WARNING", AgentLog.WARN);
Expand All @@ -129,6 +138,8 @@ public void startAgent(String appKey, String agentVersion, String reactNativeVer
}
}

String configLogLevel = (String) agentConfig.get("logLevel");
LogReporting.setLogLevel(LogLevel.valueOf(configLogLevel));
boolean useDefaultCollectorAddress =
agentConfig.get("collectorAddress") == null ||
((String) agentConfig.get("collectorAddress")).isEmpty();
Expand Down
Loading

0 comments on commit 6fda3c3

Please sign in to comment.