You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Chia-Ping Tsai (Jira)" <ji...@apache.org> on 2021/12/26 16:51:00 UTC

[jira] [Updated] (SPARK-37746) log4j2-defaults.properties is not working since log4j 2 is always initialized by default

     [ https://issues.apache.org/jira/browse/SPARK-37746?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Chia-Ping Tsai updated SPARK-37746:
-----------------------------------
    Description: 
the code used to check initialization is shown below.

      val log4j2Initialized = !LogManager.getRootLogger
        .asInstanceOf[org.apache.logging.log4j.core.Logger].getAppenders.isEmpty

That works for log4j. However, log4j2 provides a default configuration so there is always a appender (ConsoleAppender) with error level.

 

reference from [https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration]

Log4j will provide a default configuration if it cannot locate a configuration file. The default configuration, provided in the DefaultConfiguration class, will set up:
 * A [ConsoleAppender|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/ConsoleAppender.html] attached to the root logger.
 * A [PatternLayout|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html] set to the pattern "%d\{HH:mm:ss.SSS} [%t] %-5level %logger\{36} - %msg%n" attached to the ConsoleAppender

Note that by default Log4j assigns the root logger to Level.ERROR.

 

 

 

  was:
the code used to check initialization is shown below.

      val log4j2Initialized = !LogManager.getRootLogger
        .asInstanceOf[org.apache.logging.log4j.core.Logger].getAppenders.isEmpty

That works for log4j. However, log4j2 provides a default configuration so there is always a appender (ConsoleAppender) with error level.

 

according to  [https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration]

Log4j will provide a default configuration if it cannot locate a configuration file. The default configuration, provided in the DefaultConfiguration class, will set up:
 * A [ConsoleAppender|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/ConsoleAppender.html] attached to the root logger.
 * A [PatternLayout|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html] set to the pattern "%d\{HH:mm:ss.SSS} [%t] %-5level %logger\{36} - %msg%n" attached to the ConsoleAppender

Note that by default Log4j assigns the root logger to Level.ERROR.

 

 

 


> log4j2-defaults.properties is not working since log4j 2 is always initialized by default
> ----------------------------------------------------------------------------------------
>
>                 Key: SPARK-37746
>                 URL: https://issues.apache.org/jira/browse/SPARK-37746
>             Project: Spark
>          Issue Type: Bug
>          Components: Spark Core
>    Affects Versions: 3.3.0
>            Reporter: Chia-Ping Tsai
>            Priority: Minor
>
> the code used to check initialization is shown below.
>       val log4j2Initialized = !LogManager.getRootLogger
>         .asInstanceOf[org.apache.logging.log4j.core.Logger].getAppenders.isEmpty
> That works for log4j. However, log4j2 provides a default configuration so there is always a appender (ConsoleAppender) with error level.
>  
> reference from [https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration]
> Log4j will provide a default configuration if it cannot locate a configuration file. The default configuration, provided in the DefaultConfiguration class, will set up:
>  * A [ConsoleAppender|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/ConsoleAppender.html] attached to the root logger.
>  * A [PatternLayout|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html] set to the pattern "%d\{HH:mm:ss.SSS} [%t] %-5level %logger\{36} - %msg%n" attached to the ConsoleAppender
> Note that by default Log4j assigns the root logger to Level.ERROR.
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org