[ 
https://issues.apache.org/jira/browse/LOG4J2-2375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16553867#comment-16553867
 ] 

zhangjk commented on LOG4J2-2375:
---------------------------------

yes, this is a way to solve the problem, and i can use like this to solve it:  
{code:java}
lazy val p =  Producer()
{code}
but, i think, these don't really solve the problem that is static method or 
property initialization order.

and i have no idea to solve it. sry.

 

 

> When KafkaAppender is used with other KafkaProducer, there is a problem.
> ------------------------------------------------------------------------
>
>                 Key: LOG4J2-2375
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2375
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.11.0
>         Environment: scala 2.12.6 
> kafka 1.1.0 
> log4j2 2.11.0
>            Reporter: zhangjk
>            Priority: Critical
>
> hi:
> When i use the log4j2's KafkaAppender , I found a bug.  the property CONFIG 
> of the ProducerConfig is null.
> here's my code:
> log4j2.xml
> {code:java}
> <Appenders>
>     <Kafka name="Kafka" topic="test" key ="KafkaTestKey">
>         <PatternLayout pattern="%d{yyyy.MM.dd 'at' HH:mm:ss z} %-5level 
> %class{36} %L %M - %msg%xEx%n"/>
>         <Property name="bootstrap.servers">localhost:9092</Property>
>     </Kafka>
> </Appenders>
> {code}
> the main class:
> {code:java}
> object KafkaTest extends App {
>   // this is scala code.
>   // create a KafkaProducer
>   val p = new Producer
> }
> {code}
> producer code:
> {code:java}
> class Producer {
>   val props = {
>     val p = new Properties()
>     ....
>     p
>   }
>   val producer = {
>     val p = new KafkaProducer[Integer, String](props)
>     p
>   }
> }
> {code}
> The reason for this BUG is that:  the `new Producer` is first initialized, 
> and the `ProducerConfig` has a static method block, and it called the 
> `CommonClientConfigs` class. in the `CommonClientConfigs` class,  it has a 
> static Log property, so, this will initialize the Log4j2's configuration, and 
> this will call a startup method of the Appender, it actually calls the 
> KafkaAppender's method. and then the method create a new `KafkaProducer`, 
> this will create a new `ProducerConfig` instance, but the static method block 
> is not completed, so the `CONFIG` is null.  this cause the 
> `NullPointerException`  
> my english is bad, so , hope to understand what i mean
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to