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

Add a ScriptAppenderSelector to create an Appender specified by a Script

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7
    • Component/s: Appenders
    • Labels:
      None

      Description

      The use case is to create an OS-based dynamic configuration file.

      The script determines which appender to use (once), and instantiates that appender (once). There is no need for one appender to delegate to another appender.

      This feature helps you build your configuration dynamically, all from the configuration file, to determine which appenders to configure. This is different from using a RoutingAppender which creates a level of indirection and decides what to do for each log event at runtime.

      You can use multiple ScriptSelector Appenders if needed.

      For example:

      <Configuration status="WARN" name="RoutingTest">
        <Appenders>
          <ScriptAppenderSelector name="InitAppender">
            <Script language="JavaScript"><![CDATA[
               "OSNameFoo".search("Foo") > -1 ? "List2" : "List1";]]>
            </Script>
            <AppenderSet>
              <List name="List1" />
              <List name="List2" />
            </AppenderSet>
          </ScriptAppenderSelector>
        </Appenders>
        <Loggers>
          <Root level="error">
            <AppenderRef ref="InitAppender" />
          </Root>
        </Loggers>
      </Configuration>
      

      The new plugins are ScriptSelector (an Appender that builds a different ScriptSelector) and AppenderSet, a plugin with deferChildren set to true.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                garydgregory Gary Gregory
                Reporter:
                garydgregory Gary Gregory
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: