Return-Path: Delivered-To: apmail-jakarta-log4j-dev-archive@apache.org Received: (qmail 2498 invoked from network); 29 Oct 2001 18:28:21 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 29 Oct 2001 18:28:21 -0000 Received: (qmail 12533 invoked by uid 97); 29 Oct 2001 18:26:05 -0000 Delivered-To: qmlist-jakarta-log4j-dev-archive@jakarta.apache.org Received: (qmail 12495 invoked by uid 97); 29 Oct 2001 18:26:03 -0000 Mailing-List: contact log4j-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@jakarta.apache.org Received: (qmail 12471 invoked from network); 29 Oct 2001 18:26:02 -0000 Message-ID: <430F887D415DD1118C2700805F31ECF105EB179E@sota0005.cognos.com> From: "Leathers, Burton" To: 'Log4J Developers List' Subject: Proposed addition to log4j Date: Mon, 29 Oct 2001 13:25:30 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I have developed a class for use at Cognos and think it may be of value to others. In essence, it constrains the type of the "object" which may be used as the argument to the logging facility. We, at Cognos, wish to impose this constraint in order to minimize the risk of a Babel of message types being generated. I would appreciate any suggestions for improvements in the class. I am still sufficiently new to both Java and log4j that I am sure that my draft could be improved. When I have finished responding to suggestions for improvement, I will need advice on the method for a formal submission. Thanks in advance. Burton Burton Leathers Software Architect The end of the human race will be that it will eventually die of civilization. Ralph Waldo Emerson Here is the text of the class >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /** * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software * License version 1.1, a copy of which has been included with this * distribution in the LICENSE.APL file. */ // Contibutors: Burton Leathers package org.apache.log4j; import org.apache.log4j.Category; import org.apache.log4j.Priority; import org.apache.log4j.spi.CategoryFactory; public class TypedCategory extends Category { // This is the class of which arguments to logging methods must be an instance private Class baseMessageType = null; // It's enough to instantiate a factory once and for all. private static TypedFactory factory = new TypedFactory(); protected TypedCategory(String name) { super(name); } public void debug(Object p0) { if(this.baseMessageType.isInstance(p0)) { super.debug(p0); } } public void debug(Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.debug(p0, p1); } } public void error(Object p0) { if(this.baseMessageType.isInstance(p0)) { super.error(p0); } } public void error(Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.error(p0, p1); } } public void fatal(Object p0) { if(this.baseMessageType.isInstance(p0)) { super.fatal(p0); } } public void fatal(Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.fatal(p0, p1); } } /* * This method overrides {@link Category#getInstance} * by supplying its own factory type as a parameter. */ public static Category getInstance(String name, Class base) { TypedCategory t; Category c = Category.getInstance(name, factory); try { t = (TypedCategory) c; } catch (ClassCastException z) { return null; } if(t.baseMessageType == null) { t.baseMessageType = base; } return c; } /* * This method overrides {@link Category#getInstance(Class)} * by supplying its own factory type as a parameter. */ public static Category getInstance(Class clazz, Class base) { TypedCategory t; Category c = Category.getInstance(clazz.getName(), factory); try { t = (TypedCategory) c; } catch (ClassCastException z) { return null; } if(t.baseMessageType == null) { t.baseMessageType = base; } return c; } public void info(Object p0) { if(this.baseMessageType.isInstance(p0)) { super.info(p0); } } public void info(Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.info(p0, p1); } } public void log(Priority priority, Object p0) { if(this.baseMessageType.isInstance(p0)) { super.log(priority, p0); } } public void log(Priority priority, Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.log(priority, p0, p1); } } public void warn(Object p0) { if(this.baseMessageType.isInstance(p0)) { super.warn(p0); } } public void warn(Object p0, Throwable p1) { if(this.baseMessageType.isInstance(p0)) { super.warn(p0, p1); } } // Any sub-class of Category must also have its own implementation of // CategoryFactory. public static class TypedFactory implements CategoryFactory { public TypedFactory() { } public Category makeNewCategoryInstance(String name) { TypedCategory t = new TypedCategory(name); t.baseMessageType = null; return t; } } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> This message may contain privileged and/or confidential information. If you have received this e-mail in error or are not the intended recipient, you may not use, copy, disseminate, or distribute it; do not open any attachments, delete it immediately from your system and notify the sender by e-mail promptly that you have done so. Thank You. -- To unsubscribe, e-mail: For additional commands, e-mail: