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

ASF subversion and git services commented on LOG4J2-3429:
---------------------------------------------------------

Commit bf969f8b9b0aaaa24052f9b8871aebea0f21a9b1 in logging-log4j2's branch 
refs/heads/release-2.x from Piotr P. Karwasz
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=bf969f8 ]

Changelog entry for LOG4J2-3429

> 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.
> {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