Mikael’s solution is correct. Every item in the ConfigurationBuilder is a 
Component. We have “special” Components for things that are always used, such 
as Loggers and Appenders. But we can’t know about every type of Component so in 
those cases you just use the generic Component.

Ralph

> On Mar 29, 2017, at 8:26 AM, Matt Sicker <boa...@gmail.com> wrote:
> 
> Looks like a bug to me! Here's the issue: a Properties component is
> injected into a kafka appender, but there is no way to create a Property or
> Properties component directly via the configuration builder API. The top
> level properties aren't injected in the kafka appender (and manager), so
> they're unused.
> 
> Interestingly enough, I don't see a way to inject KeyValuePair components
> either (which is a similar plugin class in log4j-core).
> 
> Could you make an issue here: https://issues.apache.org/jira/browse/LOG4J2
> 
> On 29 March 2017 at 09:27, Marvin Geitner <mgeit...@novomind.com> wrote:
> 
>> Hi all,
>> 
>> I'm trying to configure the Kafka Appender with the programmatic
>> configuration described in the manuals. So I created the
>> ConfigurationFactory and set up the AppenderComponentBuilder.
>> 
>> If I execute the Application I'll get following exception:
>> 
>> Caused by: org.apache.kafka.common.config.ConfigException: Missing
>> required configuration "bootstrap.servers" which has no default value.
>> 
>> Obviously the property "bootstrap.servers" hasn't been set.
>> 
>> A builder.addProperty("bootstrap.servers", "kafka.host"); doesn't work.
>> In XML the configuration looks like <Property name="bootstrap.servers">
>> kafka.host</Property>.
>> 
>> But how do I set this in java?
>> 
>> The code looks like the following:
>> 
>>    static Configuration createConfiguration(final String name,
>> ConfigurationBuilder<BuiltConfiguration> builder) {
>> 
>>        builder.setConfigurationName(name);
>>        builder.setStatusLevel(Level.INFO);
>> 
>>        AppenderComponentBuilder kafkaBuilder = 
>> builder.newAppender("KafkaLogger
>> ", "Kafka")
>>                .addAttribute("topic", "testTopic");
>>        kafkaBuilder.add(builder.newLayout("PatternLayout")
>>                .addAttribute("pattern", "%d{HH:mm:ss:SSS} | %logger{20} |
>> %msg%n%ex{5}"));
>> 
>>        builder.add(kafkaBuilder);
>> 
>>        builder.add(builder.newRootLogger(Level.INFO).add(
>> builder.newAppenderRef("KafkaLogger")));
>> 
>>        return builder.build();
>>    }
>> 
>> Hope someone can help me.
>> 
>> Thanks and BR,
>> Marvin
>> 
> 
> 
> 
> -- 
> Matt Sicker <boa...@gmail.com>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to