[
https://issues.apache.org/jira/browse/LOG4J2-952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14721615#comment-14721615
]
Ralph Goers edited comment on LOG4J2-952 at 8/30/15 5:41 PM:
-------------------------------------------------------------
There is a huge difference between what a builder would do and what the
assembler does. When you get back a Configuration from the assemble method
there are still no Appenders, LoggerConfigs, Filters, etc. attached to it. A
builder would build the "real" objects and attach them to the configuration.
The difference is that with a builder you would see errors when you call the
build methods for each of the individual components. With the assembler you
won't see those kinds of errors until the Configuration is started. I see that
as a huge difference from how the Builder pattern normally works.
To be clear, the assembler works the same as how the XML, JSON and YAML
configurations do. The first phase to to construct the hierarchy of
configuration settings. The second phase, during the start method, is to
convert those settings into actual objects by leveraging the Plugin
builders/factories. A set of configuration builders would not work this way.
Instead each builder would construct a "real" object which would then be
attached to the configuration. The start method would then simply start each of
the objects attached to the configuration.
was (Author: [email protected]):
There is a huge difference between what a builder would do and what the
assembler does. When you get back a Configuration from the assemble method
there are still no Appenders, LoggerConfigs, Filters, etc. attached to it. A
builder would build the "real" objects and attach them to the configuration.
The difference is that with a builder you would see errors when you call the
build methods for each of the individual components. With the assembler you
won't see those kinds of errors until the Configuration is started. I see that
as a huge difference from how the Builder pattern normally works.
To be clear, the assembler works the same as how the XML, JSON and YAML
configurations do. The first phase to to construct the hierarchy of
configuration settings. The second phase, during the start method, is to
convert those settings into actual objects by leveraging the Plugin builders.
A set of configuration builders would not work this way. Instead each builder
would construct a "real" object which would then be attached to the
configuration. The start method would then simply start each of the objects
attached to the configuration.
> FAQ: How do I configure log4j2 programmatically in code without a
> configuration file?
> -------------------------------------------------------------------------------------
>
> Key: LOG4J2-952
> URL: https://issues.apache.org/jira/browse/LOG4J2-952
> Project: Log4j 2
> Issue Type: Bug
> Components: API, Configurators, Documentation
> Affects Versions: 2.1
> Reporter: Joe Merten
> Attachments: LOG4J2-952-2.patch, LOG4J2-952-3.patch,
> LOG4J2-952-4.patch, LOG4J2-952.patch
>
>
> I found [this
> link|http://logging.apache.org/log4j/2.x/faq.html#config_from_code] which
> said:
> {quote}
> You could use the static method #initialize(String contextName, ClassLoader
> loader, String configLocation) in
> org.apache.logging.log4j.core.config.Configurator. (You can pass null for the
> class loader.) Be aware that this class is not part of the public API so your
> code may break with any minor release.
> {quote}
> This documentation is unclear because it points to a member function which
> needs a filename {{configLocation}} where as the topic is »without a
> configuration file«.
> It shoud rather point to the member function
> {{org.apache.logging.log4j.core.config.Configurator.initialize(ClassLoader
> loader, ConfigurationSource source)}}.
> Example:
> {code:java}
> import org.apache.logging.log4j.core.config.ConfigurationSource;
> import org.apache.logging.log4j.core.config.Configurator;
> final String hardCodedXmlConfig =
> "<?xml version='1.0' encoding='UTF-8'?>\n" +
> "<Configuration status='INFO'>\n" +
> " <Appenders>\n" +
> " <Console name='Console' target='SYSTEM_OUT'>\n" +
> " <PatternLayout pattern='%d{HH:mm:ss.SSS} [%t] %-5level
> %logger{36} - %msg%n'/>\n" +
> " </Console>\n" +
> " </Appenders>\n" +
> " <Loggers>\n" +
> " <Root level='debug'>\n" +
> " <AppenderRef ref='Console'/>\n" +
> " </Root>\n" +
> " </Loggers>\n" +
> "</Configuration>\n";
> try {
> Configurator.initialize(null, new ConfigurationSource(new
> ByteArrayInputStream(hardCodedXmlConfig.getBytes())));
> } catch (IOException e) {
> e.printStackTrace();
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]