logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eric rose <e...@forge.com.au>
Subject Re: Default rendering and arrays
Date Mon, 03 Feb 2003 00:21:17 GMT
-----BEGIN PGP SIGNED MESSAGE-----

Ceki Gülcü wrote:
| Hi Eric,
|
| Although it is not possible to configure rendering for array classes in
| a configuration script, it is possible to do so programattically. Have
| you tried to do the following?

This was the first idea I had, but it was quickly apparent to me that
this approach is cumbersome if there are a large number of classes
involved. We develop management systems and typically we have in the
order of 100 various 'managed object' types.

A quick test of trying to log an array of doubles shows that the
suggested rendering doesn't work as suggested unless you add the statement.

~    h.setRenderer(double[].class, ar);


Unfortunately this trick doesn't work with Object[].class, and we would
have to associate the ArrayRenderer with all 100 types of managed
objects, and then have a very large if() construction to maintain.

As far as I can see the only way to render an arbitrary array is to
change the behaviour of the default renderer and let all arrays fall
through to it. What I have ended up doing, is create my own Hierarchy
with a default renderer that has the following logic:

~   if (o.getClass().isArray()) {
~      Object[] array = (Object[]) o;
~      StringBuffer buffy = new StringBuffer("[");
~      Object elt;
~      String renderedElt;
~      for (int i = 0; i < array.length-1; i++) {
~         elt = array[i];
~         renderedElt = myRenderer.findAndRender(elt);
~         buffy.append(renderedElt).append(", ");
~      }
~      elt = array[array.length-1];
~      renderedElt = myRenderer.findAndRender(elt);
~      buffy.append(renderedElt).append("]");
~      return buffy.toString();
~   } else {
~      return o.toString();
~   }

I'm still ironing out some issues on the Hierarchy side, but this has
enabled me to print arrays in useful form.

Eric

- --
Eric Rose           | If you can't see the  , they can't eat you.
eric@forge.com.au   | Don't see the  , don't see the  .

***********************************************************************
This message contains privileged and confidential information intended
only for the use of the addressee named above.  If you are not the
intended recipient of this message you must not disseminate, copy or
take any action in reliance on it.  If you have received this message
in error please notify the sender immediately.  Any views expressed in
this message are those of the individual sender, except where the
sender specifically states them to be the views of another (including
a Body Corporate).
************************************************************************


-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8
Comment: Using PGP with Mozilla - http://enigmail.mozdev.org

iQCVAwUBPj0pXjbHwE/t2hedAQE+aAP/TTI1dEPS2nYdJPZ8e/Nb2KveE1WZeDuR
shzNaHqOFQoUDrqjMQOs/Fv2NbELWQ/bX9xRnol0Uf5Fs+eXU7wwWHdKY5mOI65N
z/cR9Dw1P8AqSetPT3bTg2Va5nl6Ib1ZYP8eEDNEgklQT+iJfhuZvo4vZqqiSxzM
AhDEgN2m4w8=
=Q1/4
-----END PGP SIGNATURE-----


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


Mime
View raw message