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?
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
import org.apache.log4j.or.ObjectRenderer;
public class xy {
public static void main(String[] args) {
Logger logger = Logger.getLogger(xy.class);
BasicConfigurator.configure();
Hierarchy h = (Hierarchy) LogManager.getLoggerRepository();
ArrayRenderer ar = new ArrayRenderer();
h.setRenderer(int[].class, ar);
logger.debug(new int[] {1, 2, 3});
}
}
class ArrayRenderer implements ObjectRenderer {
public String doRender(Object o) {
if(o instanceof int[]) {
int[] a = (int[]) o;
// code could be written better but its early in the morning
StringBuffer buf = new StringBuffer();
buf.append("[");
for(int i = 0; i < a.length; i++) {
buf.append(a[i] + " ");
}
buf.append("]");
return buf.toString();
} else if (o instanceof double[])
// handle double[]
return "this is a double array";
else {
return "---"+o.toString();
}
}
}
Would the above work for you?
At 16:16 31.01.2003 +1100, eric rose wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hi,I'm new to this list so forgive me if I'm asking about something that has been kicked to death previously - I've looked through mailing list archives and googled for the topic but found nothing. I'm working on moving trace/debug logging from an in-house package to log4j, and one of the things most developers here want is a way to log an array (generally an array of primitives, as well). The default rendering behaviour is toString() which isn't particularly useful, so I've been looked into changing this. What I've ended up with is a specialised Hierarchy, which contains a specialised RendererMap, which contains a specialised DefaultRenderer - all because it's not possible to set the default rendering behaviour directly. What would be ideal, AFAICS, is to allow a setter on RendererMap.defaultRenderer or to maybe allow initial configuration of this as well as allowing new renderer mappings to be added. Are there reasons why these suggestions are a bad idea? Eric - -- Eric Rose | If you can't see the , they can't eat you. [EMAIL PROTECTED] | 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 iQCVAwUBPjl6HzbHwE/t2hedAQEJqAQAjVcrApW0cSEYNZC4OXikTWKbUeFhdOt2 xQYaoESgk3u5wbucBGiwgwNQoiE+FYHpkbsx7xEEpwy6uGEdOuQ5TFmpBzf8NPlB K8lThTPa8SQzCdXw/EBmmphYzue2t+kzeq8tmesAgrXbpjZMnE7VqPIUZ37709Ck Uv+KQRmbQuw= =PPFT -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Ceki --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]