r500155 | eross | 2007-01-26 00:56:47 -0600 (Fri, 26 Jan 2007) | 1 line

Bug 13099 - Be able to configure [Category|Logger]Factory

Index: src/java/org/apache/log4j/DefaultCategoryFactory.java
===================================================================
1,29d0
< /*
<  * Copyright 1999,2004 The Apache Software Foundation.
<  *
<  * Licensed under the Apache License, Version 2.0 (the "License");
<  * you may not use this file except in compliance with the License.
<  * You may obtain a copy of the License at
<  *
<  *      http://www.apache.org/licenses/LICENSE-2.0
<  *
<  * Unless required by applicable law or agreed to in writing, software
<  * distributed under the License is distributed on an "AS IS" BASIS,
< * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<  * See the License for the specific language governing permissions and
<  * limitations under the License.
<  */
<
< package org.apache.log4j;
<
< import org.apache.log4j.spi.LoggerFactory;
<
<
< class DefaultCategoryFactory implements LoggerFactory {
<   DefaultCategoryFactory() {
<   }
<
<   public Logger makeNewLoggerInstance(String name) {
<     return new Logger(name);
<   }
< }
Index: src/java/org/apache/log4j/PropertyConfigurator.java
===================================================================
111c111
< protected LoggerFactory loggerFactory = new DefaultCategoryFactory ();
---
>   protected LoggerFactory loggerFactory = new DefaultLoggerFactory();
Index: src/java/org/apache/log4j/spi/LoggerRepositoryEx.java
===================================================================
191a192,209
>
>   /**
> * Sets the logger factory used by [EMAIL PROTECTED] LoggerRepository#getLogger(String)}.
>    *
>    * @param loggerFactory factory to use, may not be null
>    * @throws NullPointerException factory is null
>    * @since 1.3
>    */
>   void setLoggerFactory(LoggerFactory loggerFactory);
>
>   /**
> * Returns the logger factory used by [EMAIL PROTECTED] LoggerRepository#getLogger(String)}.
>    *
>    * @return non-null factory
>    * @since 1.3
>    */
>   LoggerFactory getLoggerFactory();
>
Index: src/java/org/apache/log4j/joran/JoranConfigurator.java
===================================================================
29a30
> import org.apache.log4j.joran.action.LoggerFactoryAction;
201a203,204
> rs.addRule(new Pattern("configuration/categoryFactory"), new LoggerFactoryAction()); > rs.addRule(new Pattern("configuration/loggerFactory"), new LoggerFactoryAction());
Index: src/java/org/apache/log4j/joran/action/LoggerFactoryAction.java
===================================================================
0a1,49
> /*
>  * Copyright 1999,2004 The Apache Software Foundation.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
> * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
>
> package org.apache.log4j.joran.action;
>
> import org.apache.log4j.DefaultLoggerFactory;
> import org.apache.log4j.helpers.OptionConverter;
> import org.apache.log4j.joran.spi.ActionException;
> import org.apache.log4j.joran.spi.ExecutionContext;
> import org.apache.log4j.spi.LoggerFactory;
> import org.apache.log4j.spi.LoggerRepositoryEx;
> import org.xml.sax.Attributes;
>
> public class LoggerFactoryAction extends Action {
>
> public void begin(ExecutionContext ec, String name, Attributes attributes) throws ActionException { > LoggerRepositoryEx repository = (LoggerRepositoryEx) ec.getObject(0);
>     String factoryClassName = attributes.getValue(CLASS_ATTRIBUTE);
>
>     if (factoryClassName != null) {
>       LoggerFactory loggerFactory =
>         (LoggerFactory) OptionConverter.instantiateByClassName(
> factoryClassName, LoggerFactory.class, new DefaultLoggerFactory());
>       repository.setLoggerFactory(loggerFactory);
>     }
>     else
>     {
> getLogger().warn("Missing " + CLASS_ATTRIBUTE + " for logger factory");
>     }
>   }
>
>   @Override
> public void end(ExecutionContext ec, String name) throws ActionException {
>   }
>
> }
Index: src/java/org/apache/log4j/DefaultLoggerFactory.java
===================================================================
0a1,34
> /*
>  * Copyright 1999,2004 The Apache Software Foundation.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
> * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
>
> package org.apache.log4j;
>
> import org.apache.log4j.spi.LoggerFactory;
>
> /**
>  * Factory class that returns new [EMAIL PROTECTED] Logger} instances.
>  */
> public final class DefaultLoggerFactory implements LoggerFactory {
>
>   public DefaultLoggerFactory() {}
>
>   /**
>    * Returns a new [EMAIL PROTECTED] Logger} instance.
>    */
>   public Logger makeNewLoggerInstance(String name) {
>     return new Logger(name);
>   }
> }
Index: src/java/org/apache/log4j/Hierarchy.java
===================================================================
74c74,75
<   private LoggerFactory defaultFactory;
---
>
>   private LoggerFactory loggerFactory;
118c119
<     defaultFactory = new DefaultCategoryFactory();
---
>     loggerFactory = new DefaultLoggerFactory();
465c466
<     return getLogger(name, defaultFactory);
---
>     return getLogger(name, loggerFactory);
844a846,855
>   public void setLoggerFactory(LoggerFactory loggerFactory) {
>     if (loggerFactory == null)
>       throw new NullPointerException();
>     this.loggerFactory = loggerFactory;
>   }
>
>   public LoggerFactory getLoggerFactory() {
>     return loggerFactory;
>   }
>
Index: src/java/org/apache/log4j/xml/log4j.dtd
===================================================================
12c12,14
< (category|logger)*,root?, categoryFactory?)>
---
>                                (category|logger)*,root?,
>                                (categoryFactory|loggerFactory)?)>
>
120a123,126
> <!ELEMENT loggerFactory (param*)>
> <!ATTLIST loggerFactory
>    class        CDATA #REQUIRED>
>
Index: tests/input/xml/loggerFactory1.xml
===================================================================
0a1,18
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration>
>
> <log4j:configuration xmlns:log4j='http://logging.apache.org/'>
>
>   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern" value="%m%n"/>
>     </layout>        
>   </appender>
>
>   <root>
>     <appender-ref ref="CONSOLE" />
>   </root>
>
> <loggerFactory class="org.apache.log4j.xml.LoggerFactoryTest $Factory"/>
>
> </log4j:configuration>
\ No newline at end of file
Index: tests/input/xml/loggerFactory2.xml
===================================================================
0a1,19
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration>
>
> <log4j:configuration xmlns:log4j='http://logging.apache.org/'>
>
>   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern" value="%m%n"/>
>     </layout>        
>   </appender>
>
>   <root>
>     <appender-ref ref="CONSOLE" />
>   </root>
>
>   <!-- follow old DTD -->
> <categoryFactory class="org.apache.log4j.xml.LoggerFactoryTest $Factory"/>
>
> </log4j:configuration>
\ No newline at end of file





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to