/**
   * Call {@link PropertyConfigurator#configure(String)} with the <code>filename</code> to
   * reconfigure log4j.
   */
  public void doOnChange() {

    if (!isInitialized) return;

    new PropertyConfigurator().doConfigure(super.filename, LogManager.getLoggerRepository());

    Logger rootLogger = Logger.getRootLogger();
    Enumeration en = rootLogger.getAllAppenders();
    while (en.hasMoreElements()) {
      Appender app = (Appender) en.nextElement();
      if (app instanceof FileAppender) {
        // activate/reload options
        // set the new logfile
        String name = app.getName();
        if (name != null && name.equals("luntbuild_logfile")) {
          setLuntbuildHtmlLog(app);
        } else if (name != null && name.equals("luntbuild_txt_logfile")) {
          setLuntbuildTextLog(app);
        } else {
          String fileName = ((FileAppender) app).getFile();
          ((FileAppender) app)
              .setFile(new File(Luntbuild.installDir + "/logs/" + fileName).getAbsolutePath());
          ((FileAppender) app).activateOptions();
        }
      }
    }
    logger.info("Updated log files on change of configuration file: " + super.filename);
  }
 private void removeBufferedAppenders(org.apache.log4j.Logger logger) {
   Enumeration<?> appenders = logger.getAllAppenders();
   while (appenders.hasMoreElements()) {
     Appender appender = (Appender) appenders.nextElement();
     if (appender instanceof BufferedAppender) {
       logger.removeAppender(appender);
     }
   }
 }
Example #3
0
 private void setTraceAppenderThreshold(Logger logger, Level level) {
   Enumeration e = logger.getAllAppenders();
   while (e.hasMoreElements()) {
     AppenderSkeleton appender = (AppenderSkeleton) e.nextElement();
     if (appender.getName().equals(traceAppenderName)) {
       appender.setThreshold(level);
     }
   }
 }
Example #4
0
 @SuppressWarnings("unchecked")
 private boolean loggerContainsErrorLogAppender(Logger logger) {
   Enumeration<Appender> allAppenders = (Enumeration<Appender>) logger.getAllAppenders();
   while (allAppenders.hasMoreElements()) {
     Appender nextAppender = allAppenders.nextElement();
     if (nextAppender == errorLogAppender) {
       return true;
     }
   }
   return false;
 }
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
   try {
     context = TestBase.getContext();
     Logger root = Logger.getRootLogger();
     boolean rootIsConfigured = root.getAllAppenders().hasMoreElements();
     System.out.println("rootIsConfigured: " + rootIsConfigured);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /** {@inheritDoc} */
  @Override
  protected void setUp() throws Exception {
    Logger root = Logger.getRootLogger();

    for (Enumeration appenders = root.getAllAppenders(); appenders.hasMoreElements(); ) {
      if (appenders.nextElement() instanceof GridLog4jRollingFileAppender) return;
    }

    appender = createAppender();

    root.addAppender(appender);
  }
Example #7
0
 /** @return Returns the set of all file appenders configured */
 public static Set<File> getAllLogFiles() {
   final Set<File> logFileNames = new HashSet<File>();
   final Enumeration currentLoggers = LogManager.getCurrentLoggers();
   while (currentLoggers.hasMoreElements()) {
     Logger logger = (Logger) currentLoggers.nextElement();
     final Enumeration allAppenders = logger.getAllAppenders();
     while (allAppenders.hasMoreElements()) {
       Appender appender = (Appender) allAppenders.nextElement();
       File file = getFile(appender);
       if (file != null) {
         logFileNames.add(file);
       }
     }
   }
   return logFileNames;
 }
Example #8
0
 private synchronized void configurar() {
   if (configured) {
     //			System.err.println("configurar: configured == true");
     return;
   }
   //		System.err.println("configurar: configured == false");
   configured = true;
   // Si existe un log4j.xml / log4j.properties usarlo, si no configurar en duro
   Logger root = Logger.getRootLogger();
   if (root.getAllAppenders().hasMoreElements()) {
     System.out.println("PLoger.configurar: log4j.xml/log4j.properties");
   } else {
     // Configuracion desktop y autómatas
     root.setLevel(Level.INFO);
     Appender appender = null;
     String iniciarEn = null;
     if (System.getProperty("iniciarEn") != null) { // autómatas
       if (new File(System.getProperty("iniciarEn")).exists()) {
         iniciarEn = System.getProperty("iniciarEn");
       } else {
         System.out.println(
             System.getProperty("iniciarEn")
                 + " no existe, se va a utilizar el directorio corriente.");
       }
       try {
         String pattern = System.getProperty("PLogger.pattern", "%-4r %d [%t] %-5p %c %x - %m%n");
         String logFile = System.getProperty("PLogger.logFile", "automata.log");
         DailyRollingFileAppender drfa =
             new DailyRollingFileAppender(
                 new PatternLayout(pattern),
                 (iniciarEn == null ? "" : (iniciarEn + File.separator)) + logFile,
                 "'.'yyyy-MM-dd");
         drfa.setAppend(true);
         appender = drfa;
       } catch (IOException e) {
         e.printStackTrace();
       }
     } else { // desktops
       appender = new ConsoleAppender();
     }
     if (appender != null) {
       root.addAppender(appender);
     }
   }
 }
 @SuppressWarnings("unchecked")
 public static synchronized void syncLogs(
     String logLocation, TaskAttemptID taskid, boolean isCleanup, boolean segmented)
     throws IOException {
   System.out.flush();
   System.err.flush();
   Enumeration<Logger> allLoggers = LogManager.getCurrentLoggers();
   while (allLoggers.hasMoreElements()) {
     Logger l = allLoggers.nextElement();
     Enumeration<Appender> allAppenders = l.getAllAppenders();
     while (allAppenders.hasMoreElements()) {
       Appender a = allAppenders.nextElement();
       if (a instanceof TaskLogAppender) {
         ((TaskLogAppender) a).flush();
       }
     }
   }
   if (currentTaskid == null) {
     currentTaskid = taskid;
   }
   // set start and end
   for (LogName logName : LOGS_TRACKED_BY_INDEX_FILES) {
     if (currentTaskid != taskid) {
       // Set start = current-end
       logLengths.get(logName)[0] =
           Long.valueOf(new File(logLocation, logName.toString()).length());
     }
     // Set current end
     logLengths.get(logName)[1] =
         (segmented ? (Long.valueOf(new File(logLocation, logName.toString()).length())) : -1);
   }
   if (currentTaskid != taskid) {
     if (currentTaskid != null) {
       LOG.info(
           "Starting logging for a new task "
               + taskid
               + " in the same JVM as that of the first task "
               + logLocation);
     }
     currentTaskid = taskid;
   }
   writeToIndexFile(logLocation, taskid, isCleanup, logLengths);
 }
Example #10
0
  /**
   * Returns the full log file name for the given appender. The appender must be a FileAppender for
   * this to work.
   *
   * @param appenderName the name of the appender in the log4j configuration
   * @return null if one cant be found or the absolute file name of the appender
   */
  public static File getLogFileName(String appenderName) {
    Null.not("appenderName", appenderName);

    final Enumeration currentLoggers = LogManager.getCurrentLoggers();
    while (currentLoggers.hasMoreElements()) {
      Logger logger = (Logger) currentLoggers.nextElement();
      final Enumeration allAppenders = logger.getAllAppenders();
      while (allAppenders.hasMoreElements()) {
        Appender appender = (Appender) allAppenders.nextElement();
        if (appenderName.equals(appender.getName())) {
          File file = getFile(appender);
          if (file != null) {
            return file;
          }
        }
      }
    }
    return null;
  }
Example #11
0
  /**
   * Creates a new TestBase object.
   *
   * @param arg0 not used.
   */
  public TestBase(String arg0) {
    super(arg0);

    m_utilJavaRoot = initEnv();
    m_certHome = m_utilJavaRoot + "/test/certs";

    if (System.getProperty("utilJavaQuiet") == null) {
      PropertyConfigurator.configure(m_utilJavaRoot + "/test/conf/log4j.properties");

      // if no configuration given and logging is not setup, output to console and set level to WARN
      final Layout lay = new PatternLayout("%-5p %d{dd MMM yyyy HH:mm:ss,SSS} [%t] %c %x: %m%n");

      if (LOGGER.getAllAppenders() instanceof NullEnumeration) {
        BasicConfigurator.configure(new ConsoleAppender(lay));

        Logger parent = Logger.getLogger("org.glite.security");
        parent.setLevel(Level.WARN);
      }
    } else {
      Logger parent = Logger.getLogger("org.glite.security");
      parent.setLevel(Level.OFF);
    }
  }
Example #12
0
 @SuppressWarnings("rawtypes")
 private boolean isConfigured() {
   Logger rootLogger = Logger.getRootLogger();
   Enumeration appenders = rootLogger.getAllAppenders();
   return appenders.hasMoreElements();
 }