Skip to content

Commit

Permalink
NRLogger: Fix to honor remote log level and local log level correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Oct 30, 2024
1 parent 79e0d4b commit 28790a5
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Agent/Utilities/NRLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ + (void)log:(unsigned int)level
// @synchronized(logger) {
shouldLog = (logger->logLevels & level) != 0;
// }

if (shouldLog) {

BOOL shouldRemoteLog = (logger->remoteLogLevel & level) != 0;


if (shouldLog || shouldRemoteLog) {
[logger addLogMessage:[NSDictionary dictionaryWithObjectsAndKeys:
[self levelToString:level], NRLogMessageLevelKey,
file, NRLogMessageFileKey,
Expand All @@ -80,7 +83,10 @@ + (void)log:(unsigned int)level
shouldLog = (logger->logLevels & level) != 0;
// }

if (shouldLog) {
BOOL shouldRemoteLog = (logger->remoteLogLevel & level) != 0;


if (shouldLog || shouldRemoteLog) {
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self levelToString:level], NRLogMessageLevelKey,
file, NRLogMessageFileKey,
Expand All @@ -106,13 +112,15 @@ + (void)log:(unsigned int)level
// Filter passed logs by log level.
shouldLog = (logger->logLevels & level) != 0;

BOOL shouldRemoteLog = (logger->remoteLogLevel & level) != 0;

// Filtering of Console logs is performed based on logLevel.
// // If this is an agentLog, only print it if we are currently including the debug level.
// if (agentLogsOn) {
// shouldLog = (logger->logLevels & NRLogLevelDebug) != 0;
// }

if (shouldLog) {
if (shouldLog || shouldRemoteLog) {
[logger addLogMessage:[NSDictionary dictionaryWithObjectsAndKeys:
[self levelToString:level], NRLogMessageLevelKey,
file, NRLogMessageFileKey,
Expand Down Expand Up @@ -277,7 +285,12 @@ - (void)dealloc {
- (void)addLogMessage:(NSDictionary *)message : (BOOL) agentLogsOn {
// The static method checks the log level before we get here.
dispatch_async(logQueue, ^{
if ((self->logTargets & NRLogTargetConsole) && (![NRMAFlags shouldEnableRedirectStdOut])) {

// Only enter this first block if local logging enabled.
NSString *levelString = [message objectForKey:NRLogMessageLevelKey];
NRLogLevels level = [NRLogger stringToLevel:levelString];
BOOL shouldLog = (self->logLevels & level) != 0;
if ((self->logTargets & NRLogTargetConsole) && shouldLog && (![NRMAFlags shouldEnableRedirectStdOut])) {
NSLog(@"NewRelic(%@,%p):\t%@:%@\t%@\n\t%@",
[NewRelicInternalUtils agentVersion],
[NSThread currentThread],
Expand All @@ -287,12 +300,10 @@ - (void)addLogMessage:(NSDictionary *)message : (BOOL) agentLogsOn {
[message objectForKey:NRLogMessageMessageKey]);

}
// Only enter this block if remote logging is including this messages level.
NSString *levelString = [message objectForKey:NRLogMessageLevelKey];
NRLogLevels level = [NRLogger stringToLevel:levelString];

BOOL shouldRemoteLog = (self->remoteLogLevel & level) != 0;
// Only enter the second block if remote logging is including this messages level.

BOOL shouldRemoteLog = (self->remoteLogLevel & level) != 0;
if (agentLogsOn) {
shouldRemoteLog = (self->remoteLogLevel & NRLogLevelDebug) != 0;
}
Expand Down

0 comments on commit 28790a5

Please sign in to comment.