commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Support for JDK1.4 Logger in Commons Package
Date Wed, 03 Jul 2002 18:12:38 GMT


On Wed, 3 Jul 2002, krupa wrote:

> Date: Wed, 3 Jul 2002 15:38:03 +0100
> From: krupa <krupa@bond.co.uk>
> Reply-To: Jakarta Commons Developers List <commons-dev@jakarta.apache.org>
> To: 'Jakarta Commons Developers List' <commons-dev@jakarta.apache.org>
> Subject: RE: Support for JDK1.4 Logger in Commons Package
>
>     I have checked the 3 Logging frameworks (log4J, jdk 1.4 Logger and
> Logkit) which commons logging supports. All of the frameworks have
> Levels/Priority (at least all the frameworks have the 5 basic levels
> like DEBUG, INFO, WARN, ERROR, and FATAL). I feel the levels are basic
> need for any Logging applications.
>
>  The Commons Logging API says that it is a "Simple wrapper API around
> multiple logging APIs"(According to documentation in API).
>
>  So why do I need to have a separate wrapper for using the frameworks to
> support levels/priority in logging framework.

>  If the org.apache.commons.logging.Log has a "setLevel/setPriority"
> method, I think still it will be portable. (I might not be right because
> I didn't check all the logging frameworks available. please correct me
> if I am wrong).

Having a setLevel/setPriority would mean the need to bake into the
commons-logging API some notion of what in the heck a Level or Priority
is, making it more difficult to maintain portability, as well as more
complex to use.

Also, a basic philosophy behind commons-logging is that it should *not* be
involved in configuring what a particular logger does (i.e. what its
current level is, where the output goes, and so on).  That kind of stuff
should all be configured in the usual way for whatever logging package you
are using.

Instead, commons-logging is a very simple wrapper around the existing
configuration so that you can write applications (and libraries like the
other packages in commons) that are independent of the logger
implementation chosen.  If you need more sophisticated access to the
actual logging package you are using, you should access it directly.

>
> Regards,
> Krupa.
>

Craig


>
>
>
> -----Original Message-----
> From: rsitze@us.ibm.com [mailto:rsitze@us.ibm.com]
> Sent: 03 July 2002 14:50
> To: Jakarta Commons Developers List
> Subject: Re: Support for JDK1.4 Logger in Commons Package
>
>
>
> Regarding other factories: this is a do-ocracy - it wasn't done because it wasn't a priority
to others.
>
> There is a bug that causes commons-logger to have an unnatural bias towards Log4J. Brought
it up a while back, but I admit I didn't follow through. I'll take a look at your code &
fix the Log4J bias. Unless someone else jumps up, give me a week or so.
>
> Levels in client-API: rule 1: keep it simple. Thus, it's simple. If you want features,
you DON'T want commons logging (you loose portability). Consider using the Avalon LogKit or
Log4J with a wrapper for your target API.
>
> <ras>
>
> *******************************************
> Richard A. Sitze rsitze@us.ibm.com
> CORBA Interoperability & WebServices
> IBM WebSphere Development
>
>
> Hi there,
> I have few issues when I am using Commons Logging Package...
>
> No Factories provided other than for Log4J:
>
> There seems to be a notable omission from commons logging package when it comes to using
JDK 1.4 and other Logging mechanisms( LogKitLogger). Unless we remove Log4J from our classpath
we cannot use JDK1.4 or any other logger. Because the LogFactoryImpl uses Log4jFactory class
if the Log4J is in classpath.
>
> If this is the case the commons logging API works I don't understand the need for "commons-logging
properties" file.
>
> If there has to be a use for "commons-logging properties" file there has to be a factory
class for JDK1.4 an other logging APIs which common-logging support. Until now there is no
factory class provided for JDK1.4 in commons-logging.jar unlike org.apache.commons.logging.impl.Log4jFactory.
>
> There seems to be no update in Commons Logging side for JDK1.4 support and other logging
APIs.
>
> I have created my own JDK1.4 factory to use Logging mechanisms from JDK1.4. I have given
the code for the factory at the end of the mail. The only code change I made from Log4JFactory
is changing the getInstance method to make an instance of JDK14Logger instead of Log4JCategoryLog.
>
> The change is in 2 getInstance method.
> Log4JFactory instance=new Jdk14Logger( clazz.getName() ); Line No. 140.
> Log4JFactory instance=new Jdk14Logger( className ); Line No. 153.
>
> I have updated the commons-logging.jar with the JDK14Factory and started using the jar.
I am attaching the jar along with this mail for testing the JDK14 factory.
>
> To Use the JDK14 Factory make two entries into "commons-logging properties" file.
>
>
> org.apache.commons.logging.LogFactory = org.apache.commons.logging.impl.Jdk14Factory
> org.apache.commons.logging.Log = org.apache.commons.logging.impl.Jdk14Logger
>
>
> Changing the Level/Priority of the Logging Dynamically:
> I understand from the commons Logging Package that it is the responsibility of underlying
mechanism to support the Levels for Logging. But there is no way we can set the levels from
the client program if we are going to use org.apache.commons.logging.Log as there is no methods
to set the Levels.
>
>
>
> I really enjoyed using the commons logging API other than these two problems.
> Hope the commons group will look into the two issues and sort them out quickly.
>
>
> Regards,
> krupa.
>
> <<commons-logging.jar>>
>
>
>
>
>
> /*
> * ====================================================================
> *
> * The Apache Software License, Version 1.1
> *
> * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
> * reserved.
> *
> * Redistribution and use in source and binary forms, with or without
> * modification, are permitted provided that the following conditions
> * are met:
> *
> * 1. Redistributions of source code must retain the above copyright
> * notice, this list of conditions and the following disclaimer.
> *
> * 2. Redistributions in binary form must reproduce the above copyright
> * notice, this list of conditions and the following disclaimer in
> * the documentation and/or other materials provided with the
> * distribution.
> *
> * 3. The end-user documentation included with the redistribution, if
> * any, must include the following acknowledgement:
> * "This product includes software developed by the
> * Apache Software Foundation ( http://www.apache.org/ <http://www.apache.org/>
)."
> * Alternately, this acknowledgement may appear in the software itself,
> * if and wherever such third-party acknowledgements normally appear.
> *
> * 4. The names "The Jakarta Project", "Commons", and "Apache Software
> * Foundation" must not be used to endorse or promote products derived
> * from this software without prior written permission. For written
> * permission, please contact apache@apache.org.
> *
> * 5. Products derived from this software may not be called "Apache"
> * nor may "Apache" appear in their names without prior written
> * permission of the Apache Group.
> *
> * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> * SUCH DAMAGE.
> * ====================================================================
> *
> * This software consists of voluntary contributions made by many
> * individuals on behalf of the Apache Software Foundation. For more
> * information on the Apache Software Foundation, please see
> * < http://www.apache.org/ <http://www.apache.org/> >.
> *
> */
>
> package org.apache.commons.logging.impl;
>
>
> import java.lang.reflect.Constructor;
> import java.lang.reflect.Method;
> import java.util.Enumeration;
> import java.util.Hashtable;
> import java.util.Vector;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogConfigurationException;
> import org.apache.commons.logging.LogFactory;
> import org.apache.commons.logging.LogSource;
>
> import java.util.logging.Logger;
>
> /**
> * <p>Concrete subclass of {@link LogFactory} specific to jdk1.4.
> *
> *
> */
> public final class Jdk14Factory extends LogFactory {
>
> public Jdk14Factory() {
> super();
> }
>
> /**
> * The configuration attributes for this {@link LogFactory}.
> */
> private Hashtable attributes = new Hashtable();
>
> // previously returned instances, to avoid creation of proxies
> private Hashtable instances = new Hashtable();
>
> // --------------------------------------------------------- Public Methods
>
> /**
> * Return the configuration attribute with the specified name (if any),
> * or <code>null</code> if there is no such attribute.
> *
> * @param name Name of the attribute to return
> */
> public Object getAttribute(String name) {
> return (attributes.get(name));
> }
>
>
> /**
> * Return an array containing the names of all currently defined
> * configuration attributes. If there are no such attributes, a zero
> * length array is returned.
> */
> public String[] getAttributeNames() {
> Vector names = new Vector();
> Enumeration keys = attributes.keys();
> while (keys.hasMoreElements()) {
> names.addElement((String) keys.nextElement());
> }
> String results[] = new String[names.size()];
> for (int i = 0; i < results.length; i++) {
> results[i] = (String) names.elementAt(i);
> }
> return (results);
> }
>
>
> /**
> * Convenience method to derive a name from the specified class and
> * call <code>getInstance(String)</code> with it.
> *
> * @param clazz Class for which a suitable Log name will be derived
> *
> * @exception LogConfigurationException if a suitable <code>Log</code>
> * instance cannot be returned
> */
> public Log getInstance(Class clazz)
> throws LogConfigurationException
> {
> Log instance = (Log) instances.get(clazz);
> if( instance != null )
> return instance;
>
> instance=new Jdk14Logger( clazz.getName() );
> instances.put( clazz, instance );
> return instance;
> }
>
>
> public Log getInstance(String name)
> throws LogConfigurationException
> {
> Log instance = (Log) instances.get(name);
> if( instance != null )
> return instance;
>
> instance=new Jdk14Logger( name );
> instances.put( name, instance );
> return instance;
> }
>
>
> /**
> * Release any internal references to previously created {@link Log}
> * instances returned by this factory. This is useful environments
> * like servlet containers, which implement application reloading by
> * throwing away a ClassLoader. Dangling references to objects in that
> * class loader would prevent garbage collection.
> */
> public void release() {
>
> instances.clear();
>
> // what's the jdk1.4 mechanism to cleanup ???
> }
>
>
> /**
> * Remove any configuration attribute associated with the specified name.
> * If there is no such attribute, no action is taken.
> *
> * @param name Name of the attribute to remove
> */
> public void removeAttribute(String name) {
> attributes.remove(name);
> }
>
>
> /**
> * Set the configuration attribute with the specified name. Calling
> * this with a <code>null</code> value is equivalent to calling
> * <code>removeAttribute(name)</code>.
> *
> * @param name Name of the attribute to set
> * @param value Value of the attribute to set, or <code>null</code>
> * to remove any setting for this attribute
> */
> public void setAttribute(String name, Object value) {
> if (value == null) {
> attributes.remove(name);
> } else {
> attributes.put(name, value);
> }
> }
>
> }
>
>
> This message, together with any attachments, is
> confidential and is intended only for the use of
> the addressee(s) and may contain information
> which is covered by legal, professional or other
> privilege. If you are not the intended recipient,
> please destroy this E-mail and inform us.(See attached file: commons-logging.jar)--
> To unsubscribe, e-mail: < mailto:commons-dev-unsubscribe@jakarta.apache.org <mailto:commons-dev-unsubscribe@jakarta.apache.org>
>
> For additional commands, e-mail: < mailto:commons-dev-help@jakarta.apache.org <mailto:commons-dev-help@jakarta.apache.org>
>
>
>
>
> This message, together with any attachments, is
> confidential and is intended only for the use of
> the addressee(s) and may contain information
> which is covered by legal, professional or other
> privilege. If you are not the intended recipient,
> please destroy this E-mail and inform us.


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message