You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "David Tonhofer, m-plify S.A." <d....@m-plify.com> on 2004/07/14 00:23:13 UTC

Proposal for slight extension of PropertySetter

Hello,

Here's a slight extension of org.apache.log4j.config.PropertySetter
(or is it bloat? you decide)! Now you can use other keywords than only
'true' or 'false' to set boolean properties:


We add the following method to PropertySetter:

  /**
   * Translate a String value to a boolean
   */

  private boolean parseBoolean(String value) {
	  String lvalue = value.toLowerCase(); // non-null and trimming has already been done
	  if (lvalue.equals("yes") || lvalue.equals("true") ||
              lvalue.equals("on") || lvalue.equals("1") ||
              lvalue.equals("y") || lvalue.equals("t")) {
		  return true;
	  }
	  if (lvalue.equals("no") || lvalue.equals("false") ||
              lvalue.equals("off") || lvalue.equals("0") ||
              lvalue.equals("n") || lvalue.equals("f")) {
		  return false;
	  }
	  LogLog.error("Could not interprete '" + value + "' as a boolean...setting to 'false'");
	  return false;
  }

We modify convertArg() with a call to parseBoolean():

  /**
     Convert <code>val</code> a String parameter to an object of a
     given type.
  */

  protected
  Object convertArg(String val, Class type) {
    if(val == null)
      return null;
    String v = val.trim();
    if (String.class.isAssignableFrom(type)) {
      return val;
    } else if (Integer.TYPE.isAssignableFrom(type)) {
      return new Integer(v);
    } else if (Long.TYPE.isAssignableFrom(type)) {
      return new Long(v);
    } else if (Boolean.TYPE.isAssignableFrom(type)) {
    	return new Boolean(parseBoolean(val));
    } else if (Priority.class.isAssignableFrom(type)) {
      return OptionConverter.toLevel(v, (Level) Level.DEBUG);
    }
    return null;
  }


Good for the next version or not?

Best regards,

	-- David





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


RE: Proposal for slight extension of PropertySetter

Posted by Steve Mactaggart <st...@golftime.com.au>.
Ignore my brain deadness, missed the toLowerCase()..

Back to sleep for me. 

> -----Original Message-----
> From: Steve Mactaggart [mailto:steve@golftime.com.au] 
> Sent: Wednesday, 14 July 2004 9:46 AM
> To: 'Log4J Developers List'
> Subject: RE: Proposal for slight extension of PropertySetter
> 
> If you are going to go that far, you may as well do 
> equalsIgnoreCase in the
> comparisons to, then things like True and TRUE will still work..
> 
> Gives nice compatibility with other config files
> 
> Just my 2c
> 
> Steve
> 
> > -----Original Message-----
> > From: David Tonhofer, m-plify S.A. [mailto:d.tonhofer@m-plify.com] 
> > Sent: Wednesday, 14 July 2004 8:23 AM
> > To: log4j-dev@logging.apache.org
> > Subject: Proposal for slight extension of PropertySetter
> > 
> > Hello,
> > 
> > Here's a slight extension of org.apache.log4j.config.PropertySetter
> > (or is it bloat? you decide)! Now you can use other 
> keywords than only
> > 'true' or 'false' to set boolean properties:
> > 
> > 
> > We add the following method to PropertySetter:
> > 
> >   /**
> >    * Translate a String value to a boolean
> >    */
> > 
> >   private boolean parseBoolean(String value) {
> > 	  String lvalue = value.toLowerCase(); // non-null and 
> > trimming has already been done
> > 	  if (lvalue.equals("yes") || lvalue.equals("true") ||
> >               lvalue.equals("on") || lvalue.equals("1") ||
> >               lvalue.equals("y") || lvalue.equals("t")) {
> > 		  return true;
> > 	  }
> > 	  if (lvalue.equals("no") || lvalue.equals("false") ||
> >               lvalue.equals("off") || lvalue.equals("0") ||
> >               lvalue.equals("n") || lvalue.equals("f")) {
> > 		  return false;
> > 	  }
> > 	  LogLog.error("Could not interprete '" + value + "' as 
> > a boolean...setting to 'false'");
> > 	  return false;
> >   }
> > 
> > We modify convertArg() with a call to parseBoolean():
> > 
> >   /**
> >      Convert <code>val</code> a String parameter to an object of a
> >      given type.
> >   */
> > 
> >   protected
> >   Object convertArg(String val, Class type) {
> >     if(val == null)
> >       return null;
> >     String v = val.trim();
> >     if (String.class.isAssignableFrom(type)) {
> >       return val;
> >     } else if (Integer.TYPE.isAssignableFrom(type)) {
> >       return new Integer(v);
> >     } else if (Long.TYPE.isAssignableFrom(type)) {
> >       return new Long(v);
> >     } else if (Boolean.TYPE.isAssignableFrom(type)) {
> >     	return new Boolean(parseBoolean(val));
> >     } else if (Priority.class.isAssignableFrom(type)) {
> >       return OptionConverter.toLevel(v, (Level) Level.DEBUG);
> >     }
> >     return null;
> >   }
> > 
> > 
> > Good for the next version or not?
> > 
> > Best regards,
> > 
> > 	-- David
> > 
> > 
> > 
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


RE: Proposal for slight extension of PropertySetter

Posted by Steve Mactaggart <st...@golftime.com.au>.
If you are going to go that far, you may as well do equalsIgnoreCase in the
comparisons to, then things like True and TRUE will still work..

Gives nice compatibility with other config files

Just my 2c

Steve

> -----Original Message-----
> From: David Tonhofer, m-plify S.A. [mailto:d.tonhofer@m-plify.com] 
> Sent: Wednesday, 14 July 2004 8:23 AM
> To: log4j-dev@logging.apache.org
> Subject: Proposal for slight extension of PropertySetter
> 
> Hello,
> 
> Here's a slight extension of org.apache.log4j.config.PropertySetter
> (or is it bloat? you decide)! Now you can use other keywords than only
> 'true' or 'false' to set boolean properties:
> 
> 
> We add the following method to PropertySetter:
> 
>   /**
>    * Translate a String value to a boolean
>    */
> 
>   private boolean parseBoolean(String value) {
> 	  String lvalue = value.toLowerCase(); // non-null and 
> trimming has already been done
> 	  if (lvalue.equals("yes") || lvalue.equals("true") ||
>               lvalue.equals("on") || lvalue.equals("1") ||
>               lvalue.equals("y") || lvalue.equals("t")) {
> 		  return true;
> 	  }
> 	  if (lvalue.equals("no") || lvalue.equals("false") ||
>               lvalue.equals("off") || lvalue.equals("0") ||
>               lvalue.equals("n") || lvalue.equals("f")) {
> 		  return false;
> 	  }
> 	  LogLog.error("Could not interprete '" + value + "' as 
> a boolean...setting to 'false'");
> 	  return false;
>   }
> 
> We modify convertArg() with a call to parseBoolean():
> 
>   /**
>      Convert <code>val</code> a String parameter to an object of a
>      given type.
>   */
> 
>   protected
>   Object convertArg(String val, Class type) {
>     if(val == null)
>       return null;
>     String v = val.trim();
>     if (String.class.isAssignableFrom(type)) {
>       return val;
>     } else if (Integer.TYPE.isAssignableFrom(type)) {
>       return new Integer(v);
>     } else if (Long.TYPE.isAssignableFrom(type)) {
>       return new Long(v);
>     } else if (Boolean.TYPE.isAssignableFrom(type)) {
>     	return new Boolean(parseBoolean(val));
>     } else if (Priority.class.isAssignableFrom(type)) {
>       return OptionConverter.toLevel(v, (Level) Level.DEBUG);
>     }
>     return null;
>   }
> 
> 
> Good for the next version or not?
> 
> Best regards,
> 
> 	-- David
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Help for Log4j

Posted by Dinesh B <sh...@yahoo.com>.
hi 

I want to implement log4j in my program. my program is
running in background process on server. which is
listening for message from TIBCO RV message. whenever
new message occur i want to write it into differnet
log file. I have never implement log4j befor. can
anybody help me to solve this issue. 
If anybody paste me a sample code for implementing
log4j that will help me for going further.

I waiting for reply as early as.

thanks a lot in advance.


	
		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org