Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2888

Using AppenderComponentBuilder to Build an OutputStreamAppender

    XMLWordPrintableJSON

    Details

    • Type: Question
    • Status: Resolved
    • Priority: Minor
    • Resolution: Not A Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      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?

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dresch Daniel Resch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: