[ 
https://issues.apache.org/jira/browse/LOG4J2-3429?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Fredrick Eisele updated LOG4J2-3429:
------------------------------------
    Description: 
[https://logging.apache.org/log4j/2.x/manual/customconfig.html#Hybrid]

The sample has several syntax errors.
Some of these errors are due to an older API and some are more trivial errors.
The following fragment corrects the more critical of these errors.
Should I also make a pull request in github?
{code:java}
@Plugin(name = "MyXMLConfigurationFactory", category = "ConfigurationFactory")
@Order(10)
public class MyXMLConfigurationFactory extends ConfigurationFactory {

    /**
     * Valid file extensions for XML files.
     */
    public static final String[] SUFFIXES = new String[] {".xml", "*"};

    /**
     * Return the Configuration.
     * @param source The InputSource.
     * @return The Configuration.
     */
    @Override
    public Configuration getConfiguration(LoggerContext loggerContext, 
ConfigurationSource source) {
        return new MyXMLConfiguration(loggerContext, source);
    }

    /**
     * Returns the file suffixes for XML files.
     * @return An array of File extensions.
     */
    public String[] getSupportedTypes() {
        return SUFFIXES;
    }

}{code}
{code:java}
public class MyXMLConfiguration extends XmlConfiguration { 
  public MyXMLConfiguration(LoggerContext loggerContext, ConfigurationSource 
configSource) { 
    super(loggerContext, configSource); 
  }
  @Override protected void doConfigure() { 
    super.doConfigure(); 
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); 
    final Configuration config = ctx.getConfiguration(); 
    final Layout layout = PatternLayout.createDefaultLayout(config); 
    final Appender appender = FileAppender.createAppender("target/test.log", 
"false", "false", "File", "true", "false", "false", "4000", layout, null, 
"false", null, config); 

    appender.start(); addAppender(appender); 
    AppenderRef[] refs = new AppenderRef[] 
{AppenderRef.createAppenderRef("File", null, null)}; 
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, 
"org.apache.logging.log4j", "true", refs, null, config, null );
    loggerConfig.addAppender(appender, null, null);
    addLogger("org.apache.logging.log4j", loggerConfig);
  }
}
{code}
This still has some deprecated API calls.
The code in the pull request replaces the deprecated calls with builders.

  was:
[https://logging.apache.org/log4j/2.x/manual/customconfig.html#Hybrid]

The sample has several syntax errors.
Some of these errors are due to an older API and some are more trivial errors.
The following fragment corrects the more critical of these errors.
Should I also make a pull request in github?
{code:java}
@Plugin(name = "MyXMLConfigurationFactory", category = "ConfigurationFactory")
@Order(10)
public class MyXMLConfigurationFactory extends ConfigurationFactory {

    /**
     * Valid file extensions for XML files.
     */
    public static final String[] SUFFIXES = new String[] {".xml", "*"};

    /**
     * Return the Configuration.
     * @param source The InputSource.
     * @return The Configuration.
     */
    @Override
    public Configuration getConfiguration(LoggerContext loggerContext, 
ConfigurationSource source) {
        return new MyXMLConfiguration(loggerContext, source);
    }

    /**
     * Returns the file suffixes for XML files.
     * @return An array of File extensions.
     */
    public String[] getSupportedTypes() {
        return SUFFIXES;
    }

}{code}


{code:java}
public class MyXMLConfiguration extends XmlConfiguration { 
  public MyXMLConfiguration(LoggerContext loggerContext, ConfigurationSource 
configSource) { 
    super(loggerContext, configSource); 
  }
  @Override protected void doConfigure() { 
    super.doConfigure(); 
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); 
    final Configuration config = ctx.getConfiguration(); 
    final Layout layout = PatternLayout.createDefaultLayout(config); 
    final Appender appender = FileAppender.createAppender("target/test.log", 
"false", "false", "File", "true", "false", "false", "4000", layout, null, 
"false", null, config); 

    appender.start(); addAppender(appender); 
    AppenderRef[] refs = new AppenderRef[] 
{AppenderRef.createAppenderRef("File", null, null)}; 
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, 
"org.apache.logging.log4j", "true", refs, null, config, null );
    loggerConfig.addAppender(appender, null, null);
    addLogger("org.apache.logging.log4j", loggerConfig);
  }
}
{code}

This still has some deprecated API calls.



> Code Sample for Custom Config has Syntax Errors
> -----------------------------------------------
>
>                 Key: LOG4J2-3429
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3429
>             Project: Log4j 2
>          Issue Type: Documentation
>          Components: Reconfiguration
>    Affects Versions: 2.17.2
>            Reporter: Fredrick Eisele
>            Priority: Major
>              Labels: configuration, programmatically
>
> [https://logging.apache.org/log4j/2.x/manual/customconfig.html#Hybrid]
> The sample has several syntax errors.
> Some of these errors are due to an older API and some are more trivial errors.
> The following fragment corrects the more critical of these errors.
> Should I also make a pull request in github?
> {code:java}
> @Plugin(name = "MyXMLConfigurationFactory", category = "ConfigurationFactory")
> @Order(10)
> public class MyXMLConfigurationFactory extends ConfigurationFactory {
>     /**
>      * Valid file extensions for XML files.
>      */
>     public static final String[] SUFFIXES = new String[] {".xml", "*"};
>     /**
>      * Return the Configuration.
>      * @param source The InputSource.
>      * @return The Configuration.
>      */
>     @Override
>     public Configuration getConfiguration(LoggerContext loggerContext, 
> ConfigurationSource source) {
>         return new MyXMLConfiguration(loggerContext, source);
>     }
>     /**
>      * Returns the file suffixes for XML files.
>      * @return An array of File extensions.
>      */
>     public String[] getSupportedTypes() {
>         return SUFFIXES;
>     }
> }{code}
> {code:java}
> public class MyXMLConfiguration extends XmlConfiguration { 
>   public MyXMLConfiguration(LoggerContext loggerContext, ConfigurationSource 
> configSource) { 
>     super(loggerContext, configSource); 
>   }
>   @Override protected void doConfigure() { 
>     super.doConfigure(); 
>     final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); 
>     final Configuration config = ctx.getConfiguration(); 
>     final Layout layout = PatternLayout.createDefaultLayout(config); 
>     final Appender appender = FileAppender.createAppender("target/test.log", 
> "false", "false", "File", "true", "false", "false", "4000", layout, null, 
> "false", null, config); 
>     appender.start(); addAppender(appender); 
>     AppenderRef[] refs = new AppenderRef[] 
> {AppenderRef.createAppenderRef("File", null, null)}; 
>     LoggerConfig loggerConfig = LoggerConfig.createLogger("false", 
> Level.INFO, "org.apache.logging.log4j", "true", refs, null, config, null );
>     loggerConfig.addAppender(appender, null, null);
>     addLogger("org.apache.logging.log4j", loggerConfig);
>   }
> }
> {code}
> This still has some deprecated API calls.
> The code in the pull request replaces the deprecated calls with builders.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to