Fredrick Eisele created LOG4J2-3429:
---------------------------------------
Summary: 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
[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.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)