• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AsyncAppender类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.log4j.AsyncAppender的典型用法代码示例。如果您正苦于以下问题:Java AsyncAppender类的具体用法?Java AsyncAppender怎么用?Java AsyncAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AsyncAppender类属于org.apache.log4j包,在下文中一共展示了AsyncAppender类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: enableAsyncAuditLog

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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);        
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:FSNamesystem.java


示例2: prepareUiLogger

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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());
    });
}
 
开发者ID:satr,项目名称:intellij-idea-plugin-connector-for-aws-lambda,代码行数:18,代码来源:ConnectorViewFactory.java


示例3: makeMetricsLoggerAsync

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
/**
 * 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);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:MetricsLoggerTask.java


示例4: Close

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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();
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:25,代码来源:CacheLogger.java


示例5: createAsyncAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:SystemLog.java


示例6: getFileAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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;
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:20,代码来源:CoasterService.java


示例7: setupCluster

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:TestAuditLogs.java


示例8: testMetricsLoggerIsAsync

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:10,代码来源:TestNameNodeMetricsLogger.java


示例9: setupCluster

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:TestAuditLogs.java


示例10: testMetricsLoggerIsAsync

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@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);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:11,代码来源:TestDataNodeMetricsLogger.java


示例11: initLogger

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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);
	
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:35,代码来源:FeatureExtractor.java


示例12: testAppend

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:33,代码来源:SyslogAppenderTest.java


示例13: CreateBufferAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:42,代码来源:CacheLogger.java


示例14: getAsyncAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
private Appender getAsyncAppender(Appender... appenders) {
    AsyncAppender asyncAppender = new AsyncAppender();
    for (Appender appender : appenders) {
        asyncAppender.addAppender(appender);
    }
    return asyncAppender;
}
 
开发者ID:Heapy,项目名称:Heap,代码行数:8,代码来源:LoggingInitializer.java


示例15: start

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
@Override
public void start() {
  AsyncAppender asyncAppender = systemLog.createAsyncAppender(logName, layout);
  Logger logger = LogManager.getLogger(logName);
  logger.removeAppender(logName);
  logger.addAppender(asyncAppender);
  logger.setAdditivity(false);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:9,代码来源:PluginLogFile.java


示例16: configureLogName

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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);
    }
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:12,代码来源:CoasterService.java


示例17: addAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:7,代码来源:TestNameNodeMetricsLogger.java


示例18: replaceAppender

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
private static void replaceAppender(FileAppender fa, AsyncAppender aa) {
    Logger root = Logger.getRootLogger();
    root.removeAppender(fa);
    root.addAppender(aa);
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:6,代码来源:CoasterService.java


示例19: setupLogging

import org.apache.log4j.AsyncAppender; //导入依赖的package包/类
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;
}
 
开发者ID:swift-lang,项目名称:swift-k,代码行数:78,代码来源:Loader.java



注:本文中的org.apache.log4j.AsyncAppender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JdbcOperations类代码示例发布时间:2022-05-21
下一篇:
Java AttackEntityEvent类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap