logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Array Renderer + Configuration
Date Wed, 02 Apr 2003 13:56:54 GMT

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:Arno.Schumacher@t-mobile.de]
>Sent: Wednesday, April 02, 2003 8:14 AM
>To: 'log4j-user@jakarta.apache.org'
>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: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org




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: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Mime
View raw message