001    package com.oxygenxml.validate.nvdl.util;
002    
003    import java.io.ByteArrayInputStream;
004    import java.io.IOException;
005    import java.util.Enumeration;
006    import java.util.Properties;
007    
008    import org.apache.log4j.Logger;
009    import org.apache.log4j.PropertyConfigurator;
010    
011    /**
012     * Checks if the root category from the log4j.properties is configured. If it is
013     * not, the root category is put on the error level.
014     *
015     *
016     * @author mircea
017     * @created Feb 18, 2003
018     * 
019     */
020    public class Log4jChecker {
021    
022      /**
023       * Checks if the root category from the log4j.properties is configured. If it is
024       * not, the root category is put on the error level.
025       * 
026       */
027      public static void checkLog4j() {
028        Logger logger = Logger.getRootLogger();
029        Enumeration appenders = logger.getAllAppenders();
030        if (appenders == null || !appenders.hasMoreElements()) {
031          String propertyString =
032            "log4j.rootCategory=error, R\n"
033              + "log4j.appender.R=org.apache.log4j.ConsoleAppender\n"
034              + "log4j.appender.R.layout=org.apache.log4j.PatternLayout\n"
035              + "log4j.appender.R.layout.ConversionPattern=%d{HH:mm:ss,SSS} %r %p [ %t ] %c - %m%n";
036    
037          Properties properties = new Properties();
038          try {
039            properties.load(new ByteArrayInputStream(propertyString.getBytes("UTF8")));
040          } catch (IOException ioe) {
041            ioe.printStackTrace();
042          }
043          PropertyConfigurator.configure(properties);
044        }
045      }
046    
047    }