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

Marcono1234 updated LOG4J2-3030:
--------------------------------
    Description: 
The method 
[{{Log4jBridgeHandler.install}}|https://github.com/apache/logging-log4j2/blob/8abfd929a9c6f5ff66a734d7c37e4fd72a3baaa7/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Log4jBridgeHandler.java#L105]
 is quite useful when installing the Log4j 2 handler from code, however it has 
the following disadvantages:
# It is not synchronized
# It does not check if a Log4j 2 handler is already installed

This is problematic when a project has multiple entry points and therefore has 
to call {{Log4jBridgeHandler.install}} from multiple places (even when 
happening in a {{static}} initializer because they can run concurrently for 
different classes), or when multiple dependencies of a project call the method.
Checking if the handler is already installed (and not removing and re-adding 
it) is probably necessary to prevent race conditions where code in a different 
thread is logging while all handlers (including the old Log4j 2 handler) have 
been removed, but the new Log4j 2 handler has not been added yet.

  was:
The method 
[{{Log4jBridgeHandler.install}}|https://github.com/apache/logging-log4j2/blob/8abfd929a9c6f5ff66a734d7c37e4fd72a3baaa7/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Log4jBridgeHandler.java#L105]
 is quite useful when installing the Log4j 2 handler from code, however it has 
the following disadvantages:
# It is not synchronized
# It does not check if a Log4j 2 handler is already installed

This is problematic when a project has multiple entry points and therefore has 
to call {{Log4jBridgeHandler.install}} from multiple places (even when 
happening in a {{static}} initializer because they can run concurrently for 
different classes), or when multiple dependencies of a project call the method.
Checking if the handler is already installed (and not removing and re-adding 
it) is probably necessary to prevent race conditions where code is logging 
while all handlers (including the old Log4j 2 handler) have been removed, but 
the new Log4j 2 handler has not been added yet.


> Log4jBridgeHandler.install should be synchronized and check if already 
> installed
> --------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3030
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3030
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: JUL adapter
>    Affects Versions: 3.0.0
>            Reporter: Marcono1234
>            Priority: Major
>
> The method 
> [{{Log4jBridgeHandler.install}}|https://github.com/apache/logging-log4j2/blob/8abfd929a9c6f5ff66a734d7c37e4fd72a3baaa7/log4j-jul/src/main/java/org/apache/logging/log4j/jul/Log4jBridgeHandler.java#L105]
>  is quite useful when installing the Log4j 2 handler from code, however it 
> has the following disadvantages:
> # It is not synchronized
> # It does not check if a Log4j 2 handler is already installed
> This is problematic when a project has multiple entry points and therefore 
> has to call {{Log4jBridgeHandler.install}} from multiple places (even when 
> happening in a {{static}} initializer because they can run concurrently for 
> different classes), or when multiple dependencies of a project call the 
> method.
> Checking if the handler is already installed (and not removing and re-adding 
> it) is probably necessary to prevent race conditions where code in a 
> different thread is logging while all handlers (including the old Log4j 2 
> handler) have been removed, but the new Log4j 2 handler has not been added 
> yet.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to