Skip to content

Commit

Permalink
NR-318119 Renamed the flag to include stderr and changed the log divi…
Browse files Browse the repository at this point in the history
…der to \n\n
  • Loading branch information
mbruin-NR committed Oct 18, 2024
1 parent 7fba9ba commit 57c93a9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ + (BOOL) shouldEnableBackgroundReporting {
}

+ (BOOL) shouldEnableRedirectStdOut {
return ([NRMAFlags featureFlags] & NRFeatureFlag_RedirectStdOut) != 0;
return ([NRMAFlags featureFlags] & NRFeatureFlag_RedirectStdOutStdErr) != 0;
}

+ (NSArray<NSString*>*) namesForFlags:(NRMAFeatureFlags)flags {
Expand Down Expand Up @@ -243,7 +243,7 @@ + (BOOL) shouldEnableRedirectStdOut {
if ((flags & NRFeatureFlag_BackgroundReporting) == NRFeatureFlag_BackgroundReporting) {
[retArray addObject:@"BackgroundReporting"];
}
if ((flags & NRFeatureFlag_RedirectStdOut) == NRFeatureFlag_RedirectStdOut) {
if ((flags & NRFeatureFlag_RedirectStdOutStdErr) == NRFeatureFlag_RedirectStdOutStdErr) {
[retArray addObject:@"RedirectStdOut"];
}

Expand Down
2 changes: 1 addition & 1 deletion Agent/Public/NewRelicFeatureFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ typedef NS_OPTIONS(unsigned long long, NRMAFeatureFlags){
NRFeatureFlag_NewEventSystem = 1 << 20, // Disabled by default
NRFeatureFlag_OfflineStorage = 1 << 21, // Disabled by default
NRFeatureFlag_BackgroundReporting = 1 << 22, // Disabled by default
NRFeatureFlag_RedirectStdOut = 1 << 23, // Disabled by default
NRFeatureFlag_RedirectStdOutStdErr = 1 << 23, // Disabled by default

};
15 changes: 8 additions & 7 deletions Agent/Utilities/NRAutoLogCollector.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ + (void) restoreStandardOutputAndError {
dup2(saved_stderr, fileno(stderr));
close(saved_stdout);
close(saved_stderr);

}

+ (void) readAndParseLogFile {
Expand All @@ -65,16 +64,16 @@ + (void) readAndParseLogFile {
NSString *fileContents = [NSString stringWithContentsOfFile:[NRAutoLogCollector logFileURL].path
encoding:NSUTF8StringEncoding
error:&error];
[NRAutoLogCollector clearLogFile];

if (error) {
return;
} else if (fileContents.length == 0){
return;
}

[NRAutoLogCollector clearLogFile];

// Split the file contents into individual log entries
NSArray<NSString *> *newLogEntries = [fileContents componentsSeparatedByString:@"\n"];
NSArray<NSString *> *newLogEntries = [fileContents componentsSeparatedByString:@"\n\n"];

// Process each log entry
for (NSString *logEntry in newLogEntries) {
Expand Down Expand Up @@ -129,11 +128,13 @@ + (unsigned int) extractType:(NSString *) inputString {
// Extract the matched type value
NSRange typeRange = [match rangeAtIndex:1];
NSString *typeString = [inputString substringWithRange:typeRange];
if([typeString compare:@"Info"] == NSOrderedSame || [typeString compare:@"Default"] == NSOrderedSame){
if([typeString caseInsensitiveCompare:@"Info"] == NSOrderedSame || [typeString caseInsensitiveCompare:@"Default"] == NSOrderedSame){
return NRLogLevelInfo;
} else if([typeString compare:@"Debug"] == NSOrderedSame){
} else if([typeString caseInsensitiveCompare:@"Debug"] == NSOrderedSame){
return NRLogLevelDebug;
} else if([typeString compare:@"Error"] == NSOrderedSame || [typeString compare:@"Fault"] == NSOrderedSame){
} else if([typeString caseInsensitiveCompare:@"Warning"] == NSOrderedSame){
return NRLogLevelWarning;
} else if([typeString caseInsensitiveCompare:@"Error"] == NSOrderedSame || [typeString caseInsensitiveCompare:@"Fault"] == NSOrderedSame){
return NRLogLevelError;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Test Harness/NRTestApp/NRTestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// NewRelic.enableFeatures([NRMAFeatureFlags.NRFeatureFlag_BackgroundReporting])

// Note: Disabled by default. Enable or disable (default) flag to enable auto collect of stdout.
// NewRelic.enableFeatures([NRMAFeatureFlags.NRFeatureFlag_RedirectStdOut])
//NewRelic.enableFeatures([NRMAFeatureFlags.NRFeatureFlag_RedirectStdOutStdErr])
NewRelic.saltDeviceUUID(true)

// NewRelic.replaceDeviceIdentifier("myDeviceId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class UtilViewModel {
func testSystemLogs() {
for i in 0...100 {
triggerException.testNSLog()
print("TEST swift!!!!! \(i)")
print("TEST swift!!!!! \(i)\n")
if #available(iOS 14.0, *) {
os_log("TEST OSLog!!!!!!! \(i)")
let logger = Logger()
Expand Down

0 comments on commit 57c93a9

Please sign in to comment.