You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2008/06/20 14:27:28 UTC

DO NOT REPLY [Bug 40260] null pointer exception in pattern layout ( in spacePad method)

https://issues.apache.org/bugzilla/show_bug.cgi?id=40260


G. Ann Campbell <an...@shawinc.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ann.campbell@shawinc.com
             Status|NEEDINFO                    |ASSIGNED




--- Comment #6 from G. Ann Campbell <an...@shawinc.com>  2008-06-20 05:27:26 PST ---
I'm seeing this same problem:

Tomcat6 on Linux
log4j-1.2.7.jar loaded from WEB-INF/lib

This happens whether I stop/start the application from the Tomcat console or
undeploy/deploy a new copy of the war (also via console.) This does not happen
if I bounce Tomcat itself.

I have a singleton running in its own thread. When the application is stopped,
that singleton thread apparently remains in the JVM.

When the app restarts, it checks for the existence of an old thread and if
found, interrupts the thread.

The interrupted thread tries to log the interruption (at the INFO level) just
before the stopThread() call. The null pointer exception is thrown as a result.

Logging is not configured using PropertyConfigurator, but by hand in a company
framework I'm using:

    org.apache.log4j.LogManager.resetConfiguration();

    LogMessage logMessage = new LogMessage(LogLevel.DEBUG);
    logMessage.append("Configuring default logger");

    logFilePath = System.getProperty("log_file_path");
    if (logFilePath == null)
    {
      logFilePath = this.appAbsolutePath;
      logMessage.append("Log file environment variable could not be found -
defaulting to application absolute path.");
    }
    else
    {
      if (!logFilePath.endsWith("\\"))
        logFilePath = logFilePath + "\\";
    }

    Element rootElement = null;
    Element defaultLoggerElement = null;
    PatternLayout defaultOutputPattern = null;
    String defaultLevel = null;

    try
    {
      rootElement = JDOMHelper.getRootElement(this.getClass(), DTD_FILE,
CONFIG_FILE, true);
    }
    catch (JDOMHelperException e)
    {
      throw new ServiceException("JDOMHelperException in
LogService.reloadConfig(): " + e.getMessage());
    }

    defaultLoggerElement = rootElement.getChild(DEFAULT_LOGGER_ELEMENT);

    // See if we have any over-riding destinations for the "default" (root)
logger.
    // They will be added later, after the "destinations" are defined.
    List defaultDestinations = getDestinations(defaultLoggerElement);

    defaultOutputPattern = getOutputPattern(defaultLoggerElement, logMessage);
    defaultLevel = getLoggerLevel(defaultLoggerElement);
    logMessage.append("Creating default Console logger.");

    ConsoleAppender consoleAppender = new
ConsoleAppender(defaultOutputPattern);

    // This is used only to configure the "Root Logger".
    Logger logger = repository.getRootLogger();

    // Remove any previous appenders to reconfigure the logging options.
    logger.removeAllAppenders();
    logger.addAppender(consoleAppender);

    logMessage.append("Setting default Console Logger to " + defaultLevel + "
level");

    logger.setLevel(LogLevel.toLevel(defaultLevel));

    // Get the other loggers, if there are any.
    // Element loggers = rootElement.getChild(LOGGER_ELEMENT);

    logger.debug(logMessage.getMessage());

    List destinationList = rootElement.getChildren(DESTINATION_ELEMENT);
    if (destinationList == null || destinationList.size() == 0)
      logger.debug("No log destinations defined.");
    else
    {
      int destinationCount = destinationList.size();
      Element currentDestinationElement = null;
      for (int i = 0; i < destinationCount; i++)
        addDestination((Element) destinationList.get(i));
    }

    if (defaultDestinations != null)
    {
      logMessage = new LogMessage();

      // Clear the root logger for the over-riding appenders.
      logger.removeAllAppenders();

      String appenderName = null;
      Appender appender = null;
      for (int i = 0; i < defaultDestinations.size(); i++)
      {
        appenderName = (String) defaultDestinations.get(i);
        appender = (Appender) destinations.get(appenderName);
        if (appender == null)
          logMessage.append("Destination " + appenderName + " is not a valid
logging destination.");
        else
        {
          logMessage.append("Adding " + appenderName + " destination to default
logger.");
          logger.addAppender(appender);
        }
        appender = null;
      }
      LogLog.debug(logMessage.toString());
    }

    List loggerList = rootElement.getChildren(LOGGER_ELEMENT);

    if (loggerList == null || loggerList.size() == 0)
      logger.debug("No Loggers other than the default defined.");
    else
    {
      int loggerCount = loggerList.size();
      Element currentLoggerElement = null;
      for (int i = 0; i < loggerCount; i++)
      {
        addLogger((Element) loggerList.get(i));
      }
    }

    if (destinations != null)
    {
      destinations.clear();
      destinations = null;
    }


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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