You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2020/07/27 05:16:00 UTC

[jira] [Commented] (LOG4J2-2888) Using AppenderComponentBuilder to Build an OutputStreamAppender

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

Ralph Goers commented on LOG4J2-2888:
-------------------------------------

This really isn't an appropriate forum for asking this type of question and you don't show how you tried to use the addAttribute method.

> Using AppenderComponentBuilder to Build an OutputStreamAppender
> ---------------------------------------------------------------
>
>                 Key: LOG4J2-2888
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2888
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Configuration, Configurators
>            Reporter: Daniel Resch
>            Priority: Minor
>
> Hi all,
> I would like to programmatically create a configuration for an OutputStreamAppender using the AppenderComponentBuilder approach. I need to set the target output stream, but the .addAttribute("target", myOutputStream) method doesn't work. I have the following static method below:
> public static void configureTextStackLogger() {
> ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setStatusLevel(Level.ERROR); builder.setConfigurationName("MyApp"); builder.add(builder.newFilter("ThresholdFilter", Filter.Result.ACCEPT, Filter.Result.NEUTRAL) .addAttribute("level", Level.DEBUG));
> AppenderComponentBuilder appenderBuilder = builder.newAppender("MyTextStack", "OutputStream"); appenderBuilder.add(builder.newLayout("PatternLayout") .addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable")); OutputStreamAppender osa = (OutputStreamAppender (appenderBuilder.getBuilder())) appenderBuilder.add(builder.newFilter("MarkerFilter", Filter.Result.DENY, Filter.Result.NEUTRAL) .addAttribute("marker", "FLOW")); builder.add(appenderBuilder);
> builder.add(builder.newLogger("com.my.app", Level.INFO) .add(builder.newAppenderRef("MyTextStack")).addAttribute("additivity", false)); builder.add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef("MyTextStack")));
> Configurator.initialize(builder.build());
> }
> What do I need to do to call the setTarget in OutputStreamAppender.Builder method so I can add my OutputStream?



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