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

Bart S. commented on LOG4J2-952:
--------------------------------

Please also check 
[LOG4J2-1095|https://issues.apache.org/jira/browse/LOG4J2-1095] for the diagram 
I have made. I think it should be a good method to set this thing up.

Behrooz, you already have an internal Specification. I think this specification 
should be a public resource that results from a SpecificationBuilder. The 
specification can then be manually fed to the factory. The factory is then fed 
to the system, or getConfiguration() is called on it directly. In any case 
giving a user multiple configurations in his/her hands might enable really easy 
switching of the logging system from one state to another. The current set of 
loggers can easily be updated against another configuration. So the steps would 
be:

# obtain a SpecificationBuilder
# build a specification using the methods we have discussed
# put the specification into a factory
# feed the factory to the init system, or
# obtain configurations directly from it.

It seems to me a really great way to do this. There really should be one single 
architecture to it anyway, even if we have multiple implementations. I think 
making the Specification a public thing is the answer.

Ralph, good luck with your attempt/try/endeavour. I hope it can converge on 
something, that even if there are multiple implementations, each will have 
their strengths or beauties and both might even be able to be used at the same 
time.

Since the specification type is really only married to the factory you create, 
it should be possible for that the System does not have to know about the 
class. Or the builder. That is, unless we want a common interface for these 
things. The Builder would obviously extend (implement) core.util.Builder. The 
Specification is special for the Builder and the Factory, but who knows it 
might have common methods.

I hope this works out. Regards,

oh and Behrooz. I'm not sure everything needs to be fluid, we haven't really 
had any talk about the actual methods (of the SpecBuilder) and what would be 
nice; but I think the SpecBuilder/ConfigBuilder itself should indeed be fluent. 
I think your third point is still important.

> 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
>
> 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]

Reply via email to