[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-dev
Subject:    [jira] [Comment Edited] (LOG4J2-952) FAQ: How do I configure log4j2 programmatically in code without
From:       "Gary Gregory (JIRA)" <jira () apache ! org>
Date:       2015-08-31 18:44:45
Message-ID: JIRA.12774177.1423655285000.213206.1441046685743 () Atlassian ! JIRA
[Download RAW message or body]


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

Gary Gregory edited comment on LOG4J2-952 at 8/31/15 6:43 PM:
--------------------------------------------------------------

I can see the forest for the trees better and better in the branch now.

This is looking good!

For the first cut, I would make these classes package private:
- org.apache.logging.log4j.core.config.builder.impl.DefaultAppenderComponentBuilder
- org.apache.logging.log4j.core.config.builder.impl.DefaultAppenderRefComponentBuilder
                
- org.apache.logging.log4j.core.config.builder.impl.DefaultComponentBuilder<T extends \
                ComponentBuilder>
- org.apache.logging.log4j.core.config.builder.impl.DefaultCompositeFilterComponentBuilder
                
- org.apache.logging.log4j.core.config.builder.impl.DefaultCustomLevelComponentBuilder
                
- org.apache.logging.log4j.core.config.builder.impl.DefaultFilterComponentBuilder
- org.apache.logging.log4j.core.config.builder.impl.DefaultLayoutComponentBuilder
- org.apache.logging.log4j.core.config.builder.impl.DefaultLoggerComponentBuilder
- org.apache.logging.log4j.core.config.builder.impl.DefaultRootLoggerComponentBuilder

That gives us the flexibility to adjust the impl at will for now. I think I asked \
this before but I am not sure I was able to interpret your answer correctly with the \
above in mind.

Make P-Private?

Gary


was (Author: garydgregory):
I can see the forest for the trees better and better in the branch now.

This is looking good!

For the first cut, I would make these classes package private:
-org.apache.logging.log4j.core.config.builder.impl.DefaultAppenderComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultAppenderRefComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultComponentBuilder<T extends \
                ComponentBuilder>
-org.apache.logging.log4j.core.config.builder.impl.DefaultCompositeFilterComponentBuilder
                
-org.apache.logging.log4j.core.config.builder.impl.DefaultCustomLevelComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultFilterComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultLayoutComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultLoggerComponentBuilder
-org.apache.logging.log4j.core.config.builder.impl.DefaultRootLoggerComponentBuilder

That gives us the flexibility to adjust the impl at will for now. I think I asked \
this before but I am not sure I was able to interpret your answer correctly with the \
above in mind.

Make P-Private?

Gary

> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic