Java 类org.apache.log4j.AsyncAppender 实例源码

项目:hadoop    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:intellij-idea-plugin-connector-for-aws-lambda    文件:ConnectorViewFactory.java   
private void prepareUiLogger() {
    logger.addAppender(new AsyncAppender(){
        @Override
        public void append(LoggingEvent event) {
            super.append(event);
            logTextBox.append(String.format("\n%s: %s", event.getLevel(), event.getMessage()));
        }
    });
    logLevelList.addItem(Level.DEBUG);
    logLevelList.addItem(Level.INFO);
    logLevelList.addItem(Level.ERROR);
    logger.setLevel(Level.INFO);
    logLevelList.setSelectedItem(Level.INFO);
    logLevelList.addItemListener(e -> {
        logger.setLevel((Level) e.getItem());
    });
}
项目:aliyun-oss-hadoop-fs    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:aliyun-oss-hadoop-fs    文件:MetricsLoggerTask.java   
/**
 * Make the metrics logger async and add all pre-existing appenders to the
 * async appender.
 */
public static void makeMetricsLoggerAsync(Log metricsLog) {
  if (!(metricsLog instanceof Log4JLogger)) {
    LOG.warn("Metrics logging will not be async since "
        + "the logger is not log4j");
    return;
  }
  org.apache.log4j.Logger logger = ((Log4JLogger) metricsLog).getLogger();
  logger.setAdditivity(false); // Don't pollute actual logs with metrics dump

  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);
  }
}
项目:big-c    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:TayzGrid    文件:CacheLogger.java   
@Override
/**
 * Closes the appenders and removes them
 */
public final void Close()
{
    SetLevel("OFF");

    Enumeration enumer = log.getAllAppenders();
    if (enumer != null)
    {
        while (enumer.hasMoreElements())
        {
            Appender app = (Appender) enumer.nextElement();
            if (app instanceof AsyncAppender)
            {
                //: there is no force flush available for AsynAppenders, this is by implementation and only close is available which stops and interrupts all the threads and perfmos their operations forcefully
                AsyncAppender async = (AsyncAppender) app;
                async.close();
            }
        }
    }
    this.RemoveAllAppender();
}
项目:FlexMap    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:gerrit    文件:SystemLog.java   
public AsyncAppender createAsyncAppender(String name, Layout layout) {
  AsyncAppender async = new AsyncAppender();
  async.setName(name);
  async.setBlocking(true);
  async.setBufferSize(config.getInt("core", "asyncLoggingBufferSize", 64));
  async.setLocationInfo(false);

  if (shouldConfigure()) {
    async.addAppender(createAppender(site.logs_dir, name, layout));
  } else {
    Appender appender = LogManager.getLogger(name).getAppender(name);
    if (appender != null) {
      async.addAppender(appender);
    } else {
      log.warn(
          "No appender with the name: " + name + " was found. " + name + " logging is disabled");
    }
  }
  async.activateOptions();
  return async;
}
项目:swift-k    文件:CoasterService.java   
@SuppressWarnings("rawtypes")
protected static Appender getFileAppender() {
    Logger root = Logger.getRootLogger();
    Enumeration e = root.getAllAppenders();
    while (e.hasMoreElements()) {
        Appender a = (Appender) e.nextElement();
        if (a instanceof FileAppender) {
            return a;
        }
        if (a instanceof AsyncAppender) {
            // likely this is running in a JVM in which
            // the file appender has been replaced with
            // an async appender, so don't mess with things
            return null;
        }
    }
    logger.warn("Could not find a file appender to configure");
    return null;
}
项目:hadoop-on-lustre2    文件:FSNamesystem.java   
private static void enableAsyncAuditLog() {
  if (!(auditLog instanceof Log4JLogger)) {
    LOG.warn("Log4j is required to enable async auditlog");
    return;
  }
  Logger logger = ((Log4JLogger)auditLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  // failsafe against trying to async it more than once
  if (!appenders.isEmpty() && !(appenders.get(0) instanceof AsyncAppender)) {
    AsyncAppender asyncAppender = new AsyncAppender();
    // change logger to have an async appender containing all the
    // previously configured appenders
    for (Appender appender : appenders) {
      logger.removeAppender(appender);
      asyncAppender.addAppender(appender);
    }
    logger.addAppender(asyncAppender);        
  }
}
项目:hadoop    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:aliyun-oss-hadoop-fs    文件:TestNameNodeMetricsLogger.java   
@Test
public void testMetricsLoggerIsAsync() throws IOException {
  makeNameNode(true);
  org.apache.log4j.Logger logger =
      ((Log4JLogger) NameNode.MetricsLog).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  assertTrue(appenders.get(0) instanceof AsyncAppender);
}
项目:aliyun-oss-hadoop-fs    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:aliyun-oss-hadoop-fs    文件:TestDataNodeMetricsLogger.java   
@Test
public void testMetricsLoggerIsAsync() throws IOException {
  startDNForTest(true);
  assertNotNull(dn);
  org.apache.log4j.Logger logger = ((Log4JLogger) DataNode.METRICS_LOG)
      .getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  assertTrue(appenders.get(0) instanceof AsyncAppender);
}
项目:big-c    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:cikm16-wdvd-feature-extraction    文件:FeatureExtractor.java   
private static void initLogger(String filename) {
    final String PATTERN = "[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] [%c{1}] %m%n";

    // Stores whether an error has occured
    AppenderSkeleton errorFlagAppender = new ErrorFlagAppender();
    errorFlagAppender.setThreshold(Level.ERROR);
    errorFlagAppender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(errorFlagAppender);

    ConsoleAppender consoleAppender = new ConsoleAppender(); 
    consoleAppender.setEncoding("UTF-8");
    consoleAppender.setLayout(new PatternLayout(PATTERN)); 
    consoleAppender.setThreshold(LOG_LEVEL);
    consoleAppender.activateOptions();      
    AsyncAppender asyncConsoleAppender = new AsyncAppender();
    asyncConsoleAppender.addAppender(consoleAppender);
    asyncConsoleAppender.setBufferSize(1024);
    asyncConsoleAppender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(asyncConsoleAppender);

    FileAppender fileAppender = new FileAppender();
    fileAppender.setEncoding("UTF-8");
    fileAppender.setFile(filename);
    fileAppender.setLayout(new PatternLayout(PATTERN));
    fileAppender.setThreshold(LOG_LEVEL);
    fileAppender.setAppend(false);
    fileAppender.activateOptions();
    AsyncAppender asyncFileAppender = new AsyncAppender();
    asyncFileAppender.addAppender(fileAppender);
    asyncFileAppender.setBufferSize(1024);
    asyncFileAppender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(asyncFileAppender);

}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:cacheonix-core    文件:SyslogAppenderTest.java   
/**
 * Tests append method under normal conditions.
 */
public void testAppend() {
  SyslogAppender appender = new SyslogAppender();
  appender.setName("foo");
  appender.setThreshold(Level.INFO);
  appender.setSyslogHost("localhost");
  appender.setFacility("user");
  appender.setLayout(new PatternLayout("%m%n"));

  VectorErrorHandler errorHandler = new VectorErrorHandler();
  appender.setErrorHandler(errorHandler);
  appender.activateOptions();

  //
  //  wrap SyslogAppender with an Async since appender may
  //    hang if syslogd is not accepting network messages
  //
  AsyncAppender asyncAppender = new AsyncAppender();
  asyncAppender.addAppender(appender);
  asyncAppender.activateOptions();

  Logger logger = Logger.getRootLogger();
  logger.addAppender(asyncAppender);

  Exception e =
    new Exception("Expected exception from SyslogAppenderTest.testAppend");
  logger.info(
    "Expected message from log4j unit test SyslogAppenderTest.testAppend.", e);
  assertEquals(0, errorHandler.size());
}
项目:TayzGrid    文件:CacheLogger.java   
/**
 * Creates Buffer Appender, Responsible for storing all logging events in memory buffer and writing them down when by passing the logging events on to the file appender it
 * holds when its buffer becomes full Can also be made a lossy logger which writes only writes down to a file when a specific crieteria/condition is met
 * @param cacheName CacheName used to name the Buffer Appender
 * @param fileName File name to log into
 * @return Returns the created Appender
 */
private Appender CreateBufferAppender(String fileName)
{
    AsyncAppender appender = new AsyncAppender();
    appender.setName("BufferingForwardingAppender" + _loggerName);
    //Pick from config
    int bufferSize = bufferDefaultSize;
    RefObject<Integer> tempRef_bufferSize = new RefObject<Integer>(bufferSize);
    ReadConfig(tempRef_bufferSize);
    bufferSize = tempRef_bufferSize.argvalue;
    tangible.RefObject<Integer> tempRef_bufferSize2 = new tangible.RefObject<Integer>(bufferSize);
    if (bufferSize == bufferDefaultSize)
    {
        ReadClientConfig(tempRef_bufferSize2);
    }
    bufferSize = tempRef_bufferSize2.argvalue;

    if (bufferSize < 1)
    {
        bufferSize = bufferDefaultSize;
    }

    appender.setBufferSize(bufferSize);

    //Threshold is maintained by the logger rather than the appenders
    appender.setThreshold(Level.ALL);

    //Adds the appender to which it will pass on all the logging levels upon filling up the buffer
    appender.addAppender(CreateRollingFileAppender(fileName));

    //necessary to apply the appender property changes
    appender.activateOptions();

    return appender;
}
项目:Heap    文件:LoggingInitializer.java   
private Appender getAsyncAppender(Appender... appenders) {
    AsyncAppender asyncAppender = new AsyncAppender();
    for (Appender appender : appenders) {
        asyncAppender.addAppender(appender);
    }
    return asyncAppender;
}
项目:FlexMap    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:gerrit    文件:PluginLogFile.java   
@Override
public void start() {
  AsyncAppender asyncAppender = systemLog.createAsyncAppender(logName, layout);
  Logger logger = LogManager.getLogger(logName);
  logger.removeAppender(logName);
  logger.addAppender(asyncAppender);
  logger.setAdditivity(false);
}
项目:swift-k    文件:CoasterService.java   
public static void configureLogName() {
    FileAppender fa = (FileAppender) getFileAppender();
    if (fa != null) {
        fa.setFile(Bootstrap.LOG_DIR + File.separator + makeLogFileName());
        fa.activateOptions();

        AsyncAppender aa = new AsyncAppender();
        aa.addAppender(fa);
        replaceAppender(fa, aa);
    }
}
项目:hadoop-on-lustre2    文件:TestAuditLogs.java   
@Before
 public void setupCluster() throws Exception {
   // must configure prior to instantiating the namesystem because it
   // will reconfigure the logger if async is enabled
   configureAuditLogs();
   conf = new HdfsConfiguration();
   final long precision = 1L;
   conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
   conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
   conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
   conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
   util = new DFSTestUtil.Builder().setName("TestAuditAllowed").
       setNumFiles(20).build();
   cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
   fs = cluster.getFileSystem();
   util.createFiles(fs, fileName);

   // make sure the appender is what it's supposed to be
   Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
   @SuppressWarnings("unchecked")
   List<Appender> appenders = Collections.list(logger.getAllAppenders());
   assertEquals(1, appenders.size());
   assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

   fnames = util.getFileNames(fileName);
   util.waitReplication(fs, fileName, (short)3);
   userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}
项目:aliyun-oss-hadoop-fs    文件:TestNameNodeMetricsLogger.java   
private void addAppender(Log log, Appender appender) {
  org.apache.log4j.Logger logger = ((Log4JLogger) log).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  ((AsyncAppender) appenders.get(0)).addAppender(appender);
}
项目:aliyun-oss-hadoop-fs    文件:TestDataNodeMetricsLogger.java   
private void addAppender(Log log, Appender appender) {
  org.apache.log4j.Logger logger = ((Log4JLogger) log).getLogger();
  @SuppressWarnings("unchecked")
  List<Appender> appenders = Collections.list(logger.getAllAppenders());
  ((AsyncAppender) appenders.get(0)).addAppender(appender);
}
项目:swift-k    文件:CoasterService.java   
private static void replaceAppender(FileAppender fa, AsyncAppender aa) {
    Logger root = Logger.getRootLogger();
    root.removeAppender(fa);
    root.addAppender(aa);
}
项目:swift-k    文件:Loader.java   
protected static String setupLogging(ArgumentParser ap, SwiftConfig config, String projectName,
        String runID) throws IOException {
    String logfile;
    if (ap.isPresent(ARG_LOGFILE)) {
        logfile = ap.getStringValue(ARG_LOGFILE);
    }
    else {
        logfile = projectName + "-" + runID + ".log";
    }

    config.setProperty("logfile", logfile);

    File f = new File(logfile);

    FileAppender fa = (FileAppender) getAppender(FileAppender.class);
    AsyncAppender aa = new AsyncAppender();
    aa.addAppender(fa);

    replaceAppender(fa, aa);
    if (fa == null) {
        logger.warn("Failed to configure log file name");
    }
    else {
        fa.setFile(f.getAbsolutePath());
        if (fa instanceof LazyFileAppender) {
            ((LazyFileAppender) fa).fileNameConfigured();
        }
        fa.activateOptions();
    }
    Level level = Level.WARN;
    if (ap.isPresent(ARG_VERBOSE)) {
        level = Level.INFO;
    }
    if (ap.isPresent(ARG_DEBUG)) {
        level = Level.DEBUG;
    }
    ConsoleAppender ca = (ConsoleAppender) getAppender(ConsoleAppender.class);
    if (ca == null) {
        logger.warn("Failed to configure console log level");
    }
    else {
        ca.setThreshold(level);
        ca.activateOptions();
    }
    Logger.getLogger(Log.class).setLevel(Level.INFO);
    if (ap.isPresent(ARG_UI) && !"summary".equals(ap.getStringValue(ARG_UI))) {
        String ui = ap.getStringValue(ARG_UI);
        if ("none".equals(ui)) {
            // config should be loaded now
            SwiftConfig.getDefault().set(SwiftConfig.Key.TICKER_ENABLED, false);
        }
        else {
            ma = new MonitorAppender(projectName, ui);
            Logger.getRootLogger().addAppender(ma);
            Logger.getLogger(Log.class).setLevel(Level.DEBUG);
            Logger.getLogger(AbstractGridNode.class).setLevel(Level.DEBUG);
            Logger.getLogger(Execute.class).setLevel(Level.DEBUG);
            Logger.getLogger(SwiftExecutor.class).setLevel(Level.INFO);
            Logger.getLogger(WeightedHostScoreScheduler.class).setLevel(
                Level.INFO);
        }
        if ("TUI".equals(ui) || "ANSI".equals(ui)) {
            ca.setThreshold(Level.FATAL);
        }
    }
    else if (ap.isPresent(ARG_MINIMAL_LOGGING)) {
        Logger.getLogger("swift").setLevel(Level.WARN);
        Logger.getRootLogger().setLevel(Level.WARN);
    }
    else if (ap.isPresent(ARG_REDUCED_LOGGING)) {
        Logger.getLogger(AbstractDataNode.class).setLevel(Level.WARN);
        Logger.getLogger(New.class).setLevel(Level.WARN);
        Logger.getLogger("org.globus.cog.karajan.workflow.service").setLevel(Level.WARN);
        Logger.getLogger("swift").setLevel(Level.INFO);
    }
    return logfile;
}
项目:swift-k    文件:Loader.java   
private static void replaceAppender(FileAppender fa, AsyncAppender aa) {
    Logger root = Logger.getRootLogger();
    root.removeAppender(fa);
    root.addAppender(aa);
}