當前位置: 首頁>>代碼示例>>Java>>正文


Java Logger.getAllAppenders方法代碼示例

本文整理匯總了Java中org.apache.log4j.Logger.getAllAppenders方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.getAllAppenders方法的具體用法?Java Logger.getAllAppenders怎麽用?Java Logger.getAllAppenders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.Logger的用法示例。


在下文中一共展示了Logger.getAllAppenders方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: syncLogs

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public synchronized static void syncLogs(String logLocation, 
                                         TaskAttemptID taskid,
                                         boolean isCleanup) 
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 != taskid) {
    currentTaskid = taskid;
    resetPrevLengths(logLocation);
  }
  writeToIndexFile(logLocation, isCleanup);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TaskLog.java

示例2: flushAppenders

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static void flushAppenders(Logger l) {
  final Enumeration<Appender> allAppenders = l.getAllAppenders();
  while (allAppenders.hasMoreElements()) {
    final Appender a = allAppenders.nextElement();
    if (a instanceof Flushable) {
      try {
        ((Flushable) a).flush();
      } catch (IOException ioe) {
        System.err.println(a + ": Failed to flush!"
          + StringUtils.stringifyException(ioe));
      }
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:TaskLog.java

示例3: verifyAuditLogsRepeat

import org.apache.log4j.Logger; //導入方法依賴的package包/類
private void verifyAuditLogsRepeat(boolean expectSuccess, int ndupe)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;

  try {
    for (int i = 0; i < ndupe; i++) {
      line = reader.readLine();
      assertNotNull(line);
      assertTrue("Expected audit event not found in audit log",
          auditPattern.matcher(line).matches());
      ret &= successPattern.matcher(line).matches();
    }
    assertNull("Unexpected event in audit log", reader.readLine());
    assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
  } finally {
    reader.close();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:32,代碼來源:TestAuditLogs.java

示例4: verifyAuditLogsCheckPattern

import org.apache.log4j.Logger; //導入方法依賴的package包/類
private void verifyAuditLogsCheckPattern(boolean expectSuccess, int ndupe, Pattern pattern)
    throws IOException {
  // Turn off the logs
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.OFF);

  // Close the appenders and force all logs to be flushed
  Enumeration<?> appenders = logger.getAllAppenders();
  while (appenders.hasMoreElements()) {
    Appender appender = (Appender)appenders.nextElement();
    appender.close();
  }

  BufferedReader reader = new BufferedReader(new FileReader(auditLogFile));
  String line = null;
  boolean ret = true;
  boolean patternMatches = false;

  try {
      for (int i = 0; i < ndupe; i++) {
        line = reader.readLine();
        assertNotNull(line);
        patternMatches |= pattern.matcher(line).matches();
        ret &= successPattern.matcher(line).matches();
      }
      assertNull("Unexpected event in audit log", reader.readLine());
      assertTrue("Expected audit event not found in audit log", patternMatches);
      assertTrue("Expected success=" + expectSuccess, ret == expectSuccess);
    } finally {
      reader.close();
    }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:33,代碼來源:TestAuditLogs.java

示例5: apply

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
@SuppressWarnings( "unchecked")
public void apply() {

    /*
     * This code is run on remote agent's side
     */

    if (needsToConfigureDbAppender) {
        //first get all appenders in the root category and apply the filter
        //which will deny logging of system events
        Logger rootLogger = Logger.getRootLogger();
        Enumeration<Appender> appenders = rootLogger.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = appenders.nextElement();
            if (! (appender instanceof AbstractDbAppender)) {
                // apply this filter on all appenders which are not coming from ATS
                appender.addFilter(new NoSystemLevelEventsFilter());
            }
        }

        //attach the appender to the logging system
        Category log;
        if ("root".equals(appenderLogger)) {
            log = Logger.getRootLogger();
        } else {
            log = Logger.getLogger(appenderLogger);
        }

        log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
        
        final String caller = ThreadsPerCaller.getCaller();

        //create the new appender
        PassiveDbAppender attachedAppender = new PassiveDbAppender(caller);
        attachedAppender.setAppenderConfig(appenderConfiguration);
        //use a default pattern, as we log in the db
        attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
        attachedAppender.activateOptions();

        log.addAppender(attachedAppender);
    }

    if (needsToConfigureUserLoggers) {
        for (Entry<String, Integer> userLogger : otherLoggerLevels.entrySet()) {
            /* 
             * We want to set the level of this logger.
             * It is not important if this logger is already attached to log4j system or 
             * not as the next code will obtain it(in case logger exists) or will create it 
             * and then will set its level
             */
            Logger.getLogger(userLogger.getKey())
                  .setLevel(Level.toLevel(userLogger.getValue()));
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:57,代碼來源:RemoteLoggingConfigurator.java

示例6: revert

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
@SuppressWarnings( "unchecked")
public void revert() {

    /*
     * This code is run on remote agent's side
     */

    /*
     * The outer code will call this method when the "needs applying" method return true.
     * 
     * Currently we could come here because of 2 reasons:
     *  - the DB appenders must be reconfigured
     *  - the user loggers must be reconfigured
     */

    if (appenderLogger != null && needsToConfigureDbAppender) {
        // there is a DB appender and it is out-of-date

        //remove the filter which will deny logging of system events
        Logger rootLogger = Logger.getRootLogger();
        Enumeration<Appender> appenders = rootLogger.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = appenders.nextElement();

            //remove the filter
            //FIXME:This is very risky, as someone may have added other filters
            //the current implementation of the filter chain in log4j will not allow
            //us to easily remove a single filter
            appender.clearFilters();
        }

        Category log;
        if ("root".equals(appenderLogger)) {
            log = Logger.getRootLogger();
        } else {
            log = Logger.getLogger(appenderLogger);
        }

        Appender dbAppender = PassiveDbAppender.getCurrentInstance(ThreadsPerCaller.getCaller());
        if (dbAppender != null) {
            //close the appender
            dbAppender.close();

            //remove it
            log.removeAppender(dbAppender);
        }
    }

    // in case we must reconfigure the custom loggers, here we should remove them from log4j, 
    // but log4j does not provide a way to do it - so we do nothing here 
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:53,代碼來源:RemoteLoggingConfigurator.java

示例7: figureoutLogConfiguration

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {

    Enumeration<Appender> appenders = Logger.getAllAppenders();

    while (appenders != null && appenders.hasMoreElements()) {

        LogProfileInfo logProfileInfo = new LogProfileInfo();

        if (appid != null) {
            logProfileInfo.setAppId(appid);
        }

        logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);

        Map<String, String> attributes = new HashMap<String, String>();

        attributes.put(LogProfileInfo.ENGINE, "log4j");

        Appender appender = appenders.nextElement();

        if (!(appender instanceof FileAppender)) {
            continue;
        }

        FileAppender fileAppender = (FileAppender) appender;

        Layout layout = fileAppender.getLayout();

        if (null != layout) {

            if (layout instanceof PatternLayout) {
                PatternLayout patternLayout = (PatternLayout) fileAppender.getLayout();
                attributes.put(LogProfileInfo.PATTERN, patternLayout.getConversionPattern());
            }
            else if (layout instanceof HTMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
            }
            else if (layout instanceof SimpleLayout) {
                attributes.put(LogProfileInfo.PATTERN, "SimpleLayout");
            }
            else if (layout instanceof TTCCLayout) {
                attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
            }
        }

        boolean useBuffIO = fileAppender.getBufferedIO();

        if (useBuffIO == true) {
            attributes.put(LogProfileInfo.BUFFER_SIZE, String.valueOf(fileAppender.getBufferSize()));
            attributes.put(LogProfileInfo.BUFFRT_IO, String.valueOf(useBuffIO));
        }

        logProfileInfo.setFilePath(fileAppender.getFile());
        logProfileInfo.setAttributes(attributes);

        list.add(logProfileInfo);

    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:61,代碼來源:Log4jHookProxy.java


注:本文中的org.apache.log4j.Logger.getAllAppenders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。