CVS: plexus-container-new/src/test/org/apache/plexus/logging/log4j Log4JLoggerManagerTest.java,1.2,1.3

[email protected] Sat, 31 May 2003 10:20:13 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/logging/log4j
In directory eng.werken.com:/tmp/cvs-serv21816/src/test/org/apache/plexus/logging/log4j

Modified Files:
	Log4JLoggerManagerTest.java 
Log Message:
The ConsoleLoggerManager can be configured with a logging threshold
level via the plexus.conf configuration file.  This enables a user to
control the level of logging messages displayed on the console.  For
example:

  <logging>
    <implementation>org.apache.plexus.logging.ConsoleLoggerManager</implementation>
    <logger>
      <threshold>DEBUG</threshold>
    </logger>
  </logging>

In order to accomodate the change, the LoggerManagerFactory, which calls
configure() on a specific LoggerManager, now passes only the <logging>
configuration block instead of the full plexus.conf configuration block.
This makes more sense because each implementation of a LoggerManager no
longer has to take the extra step of conf.getChild("logging").

On a side note, my primary goal is to enhance the logging system so each
component can specify its own logging level.  However, I have not gone
through all of the plexus code to start making these changes.  I'm
slowly making my way through.  My initial thoughts are:

- Add a <logging> block which could contain a logger-specific
  configuration.  This block would then used by the LoggerManager when
  creating the Logger for this component. 

For example:

<component>
  <role>org.apache.plexus.examples.simple.HelloWorld</role>
  <implementation>org.apache.plexus.examples.simple.DefaultHelloWorld</implementation>
  <logging>
    <priority>DEBUG</priority>
  </logging>
  <configuration>
    <greeting>Hello World!</greeting>
  </configuration>
</component>

The above <logging> block might be suitable for use with the
ConsoleLogger or Log4JLogger.  In another example, lets say I have a
SylogLogger, perhaps its logging configuration block could take a
ipaddress of where the messages should be logged.

<component>
  <role>org.apache.plexus.examples.simple.HelloWorld</role>
  <implementation>org.apache.plexus.examples.simple.DefaultHelloWorld</implementation>
  <logging>
    <priority>DEBUG</priority>
    <ipaddress>10.10.10.10</ipaddress>
  </logging>
  <configuration>
    <greeting>Hello World!</greeting>
  </configuration>
</component>

One last example, one could specify the Log4J appender to use (assuming
the appenders were defined up top in the logger manager configuration
block), here is a full plexus conf example:

<plexus>

  <logging>
    <logger>
      <appender-id>default</appender-id>
      <priority>INFO</priority>
    </logger>

    <appender>
      <id>default</id>
      <type>file</type>
      <type-configuration>
        <file>${plexus.home}/logs/plexus.log</file>
        <append>true</append>
      </type-configuration>
      <threshold>INFO</threshold>
      <layout>pattern-layout</layout>
      <conversion-pattern>%-4r [%t] %-5p %c %x - %m%n</conversion-pattern>
    </appender>
  </logging>

  <component>
    <role>org.apache.plexus.examples.simple.HelloWorld</role>
    <implementation>org.apache.plexus.examples.simple.DefaultHelloWorld</implementation>
    <logging>
      <priority>DEBUG</priority>
      <appender-id>default</appender-id>
    </logging>
    <configuration>
      <greeting>Hello World!</greeting>
    </configuration>
  </component>
 
</plexus>

Basically, in a nutshell, the <logging> block of the component
descriptor could be used in a LoggerManager-specific manner when
creating Loggers for components.  

Just some thoughts of what I am going to be working towards.  Does this
seem reasonable?




Index: Log4JLoggerManagerTest.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/logging/log4j/Log4JLoggerManagerTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Log4JLoggerManagerTest.java	3 May 2003 00:40:38 -0000	1.2
+++ Log4JLoggerManagerTest.java	31 May 2003 15:20:11 -0000	1.3
@@ -3,6 +3,7 @@
 import junit.framework.TestCase;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.plexus.configuration.XmlPullConfigurationBuilder;
+import org.apache.plexus.logging.LoggerManagerFactory;
 
 import java.io.InputStreamReader;
 import java.util.Properties;
@@ -25,7 +26,7 @@
         Configuration c = builder.parse(
             new InputStreamReader( Log4JLoggerManagerTest.class.getResourceAsStream( "plexus.conf" ) ) );
 
-        loggerManager.configure( c );
+        loggerManager.configure( c.getChild( LoggerManagerFactory.LOGGING_TAG ) );
         loggerManager.initialize();
 
         Properties p = loggerManager.getLog4JProperties();