logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brown, James" <james.br...@ca.unisys.com>
Subject PropertyConfigurator and Logger Factories
Date Tue, 06 Apr 2004 11:40:36 GMT
According to  http://logging.apache.org/log4j/docs/api/org/apache/log4j/PropertyConfigurator.html#doConfigure(java.lang.String,%20org.apache.log4j.spi.LoggerRepository):
  "The usage of custom logger factories is discouraged and no longer documented."

What is the alternative?

Much more detail ...

However, I have run into an instance where I need to utilize this mechanism.  Otherwise I
receive ClassCastExceptions when trying to set the level for classes via:
  log4j.logger.class.of.the.day=[level]

I have defined a LoggerFactory as such:

package xyz;

public class LoggerFactory implements org.apache.log4j.spi.LoggerFactory {

  /**
   * Creates a new ca.acol.common.logging.Logger instance.
   * @param name the name of the logger instance.
   * @return an org.apache.log4j.Logger
   */
  public org.apache.log4j.Logger makeNewLoggerInstance(String name) {
    return new Logger(name);
  }
}

And xyz.Logger is defined as:
package xyz;
public class Logger extends org.apache.log4j.Logger {
  private static LoggerFactory xyzFactory = new LoggerFactory();

  private LoggerContext loggerContext;

  protected Logger(String name) {
    super(name);
  }

  public static Logger getXYZLogger(String name) {
    return (Logger) Logger.getLogger(name, acolFactory);
  }

  public static Logger getXYZLogger(Class clazz) {
    return (Logger) Logger.getLogger(clazz.getName(), acolFactory);
  }

  public void setLoggerContext(LoggerContext logContext) {
    loggerContext = logContext;
  }

  protected void forcedLog(String fqcn, Priority priority, Object message, Throwable t) {
    if (loggerContext != null) {
      NDC.push(loggerContext.getMessage());
    }
    super.forcedLog(fqcn, priority, message, t);
    if (loggerContext != null) {
      NDC.pop();
    }
  }

  public LoggerContext getLoggerContext() {
    return loggerContext;
  }
}



If I have a class abc.MyClass:
package abc;
public class MyClass {
  private static final Logger log =
    xyz.Logger.getXYZLogger(MyClass.class);
  .
  .
  .
}


If I attempt to put the following in the log4j.properties file, I receive a ClassCastException
from xyz.Logger.getXYZLogger(Class clazz):
  log4j.logger.xyz.MyClass=ERROR

Unless I also add the following:
  log4j.loggerFactory=xyz.LoggerFactory

Any help would be greatly appreciated.

-- James

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers. 


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


Mime
View raw message