You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by sreenivas velagapudi <sr...@yahoo.com> on 2006/02/14 07:44:57 UTC

extending LogFactoryImpl

Hi,
I am using commons-logging and log4j
My commons-logging .properties is as shown below,

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
org.apache.commons.logging.Log=com.logging.log4j.Log4jAdapter

I want to write one custom level called AUDIT in log4j

The problem is, that the log level is hard coded into
the method names of log interface of commons-logging
You have "log.error, log.debug, " on the Log
interface.

So let's extend it with a new level called "AUDIT"
     /**
     * <p> Is AUDIT logging currently enabled? </p>
     *
    * <p> Call this method to prevent having to
perform expensive operations      * (for example,
<code>String</code> concatination)
      * when the log level is more than the fatal
level. </p>
      */
     public boolean isAuditEnabled();

    /**
     * <p> Log a message with AUDIT log level. </p>
     *
    * @param message log this message
     */
    public void Audit(Object message);

Which would use a "Audit" log level set by a
In the Log4JAdapter this would be quite a simple
implementation:

public void audit(Object message) {
   logger.log(FQCN, CustomLevel.Audit, message, null);
}

so can you please tellme how can i extend the
LogFactoryImpl and create the code for me, if u have
please send the code to me

currently i am using this way

private static final Log log =
                LogFactory.getLog(ManagerImpl.class);

                if (log.isDebugEnabled())
                        log.debug(props);

I need to add and call new level Audit which i already
created in log4j, i should use this way


                                if (
log.isAuditEnabled())
                        log.audit(props);



Thanks
Sreenivas


	
	
		
__________________________________ 
Do you Yahoo!? 
New and Improved Yahoo! Mail - 1GB free storage! 
http://sg.whatsnew.mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: extending LogFactoryImpl

Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2006-02-14 at 14:44 +0800, sreenivas velagapudi wrote:
> Hi,
> I am using commons-logging and log4j
> My commons-logging .properties is as shown below,
> 
> org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
> org.apache.commons.logging.Log=com.logging.log4j.Log4jAdapter
> 
> I want to write one custom level called AUDIT in log4j
> 
> The problem is, that the log level is hard coded into
> the method names of log interface of commons-logging
> You have "log.error, log.debug, " on the Log
> interface.

Commons-logging is not intended to be extended with additional log
levels. Commons-logging is meant to isolate code from the underlying
logging library, so it makes no sense to allow it to be extended to
handle custom logging levels that not all logging libraries support.

If you wish to use a custom log4j level, then I suggest your code use
log4j directly rather than using commons logging.

If you are absolutely determined to do this, then you don't need to
modify the LogFactoryImpl at all. You've already defined a custom Log
implementation and set up commons-logging.properties to point to it, so
you can just cast the result:

private static final Log4jAdapter log =
     (Log4jAdapter) LogFactory.getLog(ManagerImpl.class);

Of course this will throw an exception if you ever try to use it with
some other logging library, which makes it rather pointless. As I
suggested above, just use log4j directly.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org