viirya commented on a change in pull request #35080:
URL: https://github.com/apache/spark/pull/35080#discussion_r777144547



##########
File path: core/src/main/scala/org/apache/spark/internal/Logging.scala
##########
@@ -259,18 +259,25 @@ private[spark] object Logging {
       } else if 
(logEvent.getLevel.isMoreSpecificThan(Logging.sparkShellThresholdLevel)) {
         Filter.Result.NEUTRAL
       } else {
-        var logger = LogManager.getLogger(logEvent.getLoggerName)
-          .asInstanceOf[Log4jLogger]
-        while (logger.getParent() != null) {
-          if (logger.getLevel != null || !logger.getAppenders.isEmpty) {
+        val logger = 
LogManager.getLogger(logEvent.getLoggerName).asInstanceOf[Log4jLogger]
+        if (loggerWithCustomConfig(logger)) {
             return Filter.Result.NEUTRAL
-          }
-          logger = logger.getParent()
         }
         Filter.Result.DENY
       }
     }
 
+    // Return true if the logger has custom configuration. It depends on:
+    // 1. If the logger isn't attached with root logger config (i.e., with 
custom configuration), or
+    // 2. the logger level is different to root config level (i.e., it is 
changed programmingly).
+    //
+    // Note that if a logger is programmingly changed log level but set to 
same level as root config
+    // level, we cannot tell if it is with custom configuration.
+    private def loggerWithCustomConfig(logger: Log4jLogger): Boolean = {
+      val rootConfig = LogManager.getRootLogger.asInstanceOf[Log4jLogger].get()
+      logger.get() != rootConfig || logger.getLevel != rootConfig.getLevel()

Review comment:
       > Is it possible that logger.get() != rootConfig is false but 
logger.getLevel != rootConfig.getLevel() is true?
   
   Yes, this is the case 2 in the comment. For a logger that was changed the 
level by `setLevel`, although it is attached with root config, but its level is 
different to root config's level. I have added test case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to