Howdy, I don't like the IllegalArgumentException. It's only a personal preference, and obviously it's your renderer so you can do whatever you want with it, but I don't think renderers in log4j should ever throw exceptions. In this particular case, I would like to see something like
"The argument " + array + " is not an array!" returned from the renderer. Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Schumacher Arno,E2 [mailto:[EMAIL PROTECTED] >Sent: Wednesday, April 02, 2003 8:14 AM >To: '[EMAIL PROTECTED]' >Subject: Array Renderer + Configuration > >I think there was some discussion about that >in 1/2003; don't know whether there was already >a proposal for rendering arrays plus XML-configuration. >Here is my suggestion for that. It should work fine >for all kind of arrays (int[], String[], Object[],...). >Have fun. > >Arno Schumacher / Syngenio AG > > >Configuration: > ><?xml version="1.0" encoding="UTF-8" ?> ><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> > ><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> > > <renderer renderingClass="de.tmobile.portal.log4j.ArrayRenderer" > renderedClass="[Ljava.lang.Object;"/> > >[..] ></log4j:configuration> > >Java: > >package de.tmobile.portal.log4j; > >import java.lang.reflect.Array; > >import org.apache.log4j.or.ObjectRenderer; > >public class ArrayRenderer implements ObjectRenderer >{ > > /* (non-Javadoc) > * @see org.apache.log4j.or.ObjectRenderer#doRender(java.lang.Object) > */ > public String doRender(Object arg) > { > return asString( arg ); > } > > /** > * Returns a <code>String </code>representation of the provided array >object. > * @param array an array > * @return a <code>String </code>representation of the passed array > * @exception a <code>IllegalArgumentException</code> in case the >object passed > * as parameter is not an array. > */ > private static String asString(Object array) > { > if (array == null) > { > return "null"; > } > else > { > if (array.getClass().isArray()) > { > int iLength = Array.getLength(array); > if (iLength == 0) > { > return "[]"; > } > else > { > StringBuffer sb = new StringBuffer(); > > for (int i = 0; i < iLength; i++) > { > sb.append("["); > Object o = Array.get(array, i); > String str; > try > { > if (o == null) > { > str = "null"; > } > else if (o.getClass().isArray()) > { > str = asString(o); > } > else > { > str = o.toString(); > } > } > catch (Throwable t) > { > str = "?"; > } > sb.append(str); > sb.append("]"); > } > > return sb.toString(); > } > } > else > { > throw new IllegalArgumentException("Not an array: " + >array); > } > } > } >} > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
