当前位置: 首页>>代码示例>>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;未经允许,请勿转载。