org.apache.log4j.Appender.close()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(221)

本文整理了Java中org.apache.log4j.Appender.close()方法的一些代码示例,展示了Appender.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Appender.close()方法的具体详情如下:
包路径:org.apache.log4j.Appender
类名称:Appender
方法名:close

Appender.close介绍

[英]Release any resources allocated within the appender such as file handles, network connections, etc.

It is a programming error to append to a closed appender.
[中]释放appender中分配的任何资源,如文件句柄、网络连接等。
追加到关闭的追加器是一个编程错误。

代码示例

代码示例来源:origin: log4j/log4j

/**
 * Remove and close all previously attached appenders.
 * */
public
void removeAllAppenders() {
 if(appenderList != null) {
  int len = appenderList.size();      
  for(int i = 0; i < len; i++) {
 Appender a = (Appender) appenderList.elementAt(i);
 a.close();
  }
  appenderList.removeAllElements();
  appenderList = null;      
 }
}

代码示例来源:origin: log4j/log4j

/**
  Close all attached appenders implementing the AppenderAttachable
  interface.
  @since 1.0
*/
synchronized
void closeNestedAppenders() {
 Enumeration enumeration = this.getAllAppenders();
 if(enumeration != null) {
  while(enumeration.hasMoreElements()) {
 Appender a = (Appender) enumeration.nextElement();
 if(a instanceof AppenderAttachable) {
  a.close();
 }
  }
 }
}

代码示例来源:origin: log4j/log4j

/**
 * Close this <code>AsyncAppender</code> by interrupting the dispatcher
 * thread which will process all pending events before exiting.
 */
public void close() {
 closed = true;
 //
 //    close all attached appenders.
 //
 synchronized (appenders) {
  Enumeration iter = appenders.getAllAppenders();
  if (iter != null) {
   while (iter.hasMoreElements()) {
    Object next = iter.nextElement();
    if (next instanceof Appender) {
     ((Appender) next).close();
    }
   }
  }
 }
}

代码示例来源:origin: log4j/log4j

((Appender) next).close();

代码示例来源:origin: apache/ignite

/**
 * Cluster topology mismatch shall result in DataStreamer retrying cache update with the latest topology and
 * no error logged to the console.
 *
 * @throws Exception if failed
 */
@Test
public void testRetryWhenTopologyMismatch() throws Exception {
  final int KEY = 1;
  final String VAL = "1";
  cnt = 0;
  StringWriter logWriter = new StringWriter();
  Appender logAppender = new WriterAppender(new SimpleLayout(), logWriter);
  Logger.getRootLogger().addAppender(logAppender);
  startGrids(MAX_CACHE_COUNT - 1); // cache-enabled nodes
  try (Ignite ignite = startGrid(MAX_CACHE_COUNT);
     IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
    needStaleTop = true; // simulate stale topology for the next action
    streamer.addData(KEY, VAL);
  } finally {
    needStaleTop = false;
    logWriter.flush();
    Logger.getRootLogger().removeAppender(logAppender);
    logAppender.close();
  }
  assertFalse(logWriter.toString().contains("DataStreamer will retry data transfer at stable topology"));
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Remove and close all previously attached appenders.
 * */
public
void removeAllAppenders() {
 if(appenderList != null) {
  int len = appenderList.size();      
  for(int i = 0; i < len; i++) {
 Appender a = (Appender) appenderList.elementAt(i);
 a.close();
  }
  appenderList.removeAllElements();
  appenderList = null;      
 }
}

代码示例来源:origin: apache/log4j

/**
 * Remove and close all previously attached appenders.
 * */
public
void removeAllAppenders() {
 if(appenderList != null) {
  int len = appenderList.size();      
  for(int i = 0; i < len; i++) {
 Appender a = (Appender) appenderList.elementAt(i);
 a.close();
  }
  appenderList.removeAllElements();
  appenderList = null;      
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  Close all attached appenders implementing the AppenderAttachable
  interface.
  @since 1.0
*/
synchronized
void closeNestedAppenders() {
 Enumeration enumeration = this.getAllAppenders();
 if(enumeration != null) {
  while(enumeration.hasMoreElements()) {
 Appender a = (Appender) enumeration.nextElement();
 if(a instanceof AppenderAttachable) {
  a.close();
 }
  }
 }
}

代码示例来源:origin: apache/log4j

/**
  Close all attached appenders implementing the AppenderAttachable
  interface.
  @since 1.0
*/
synchronized
void closeNestedAppenders() {
 Enumeration enumeration = this.getAllAppenders();
 if(enumeration != null) {
  while(enumeration.hasMoreElements()) {
 Appender a = (Appender) enumeration.nextElement();
 if(a instanceof AppenderAttachable) {
  a.close();
 }
  }
 }
}

代码示例来源:origin: apache/log4j

/**
 * Close this <code>AsyncAppender</code> by interrupting the dispatcher
 * thread which will process all pending events before exiting.
 */
public void close() {
 closed = true;
 //
 //    close all attached appenders.
 //
 synchronized (appenders) {
  Enumeration iter = appenders.getAllAppenders();
  if (iter != null) {
   while (iter.hasMoreElements()) {
    Object next = iter.nextElement();
    if (next instanceof Appender) {
     ((Appender) next).close();
    }
   }
  }
 }
}

代码示例来源:origin: apache/log4j

((Appender) next).close();

代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service

public
void closeAppenders() {
  for (Appender appender : appenderList) {
    appender.close();
  }
}

代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service

/**
 * Remove and close all previously attached appenders.
 * */
public
void removeAllAppenders() {
  for (Appender a : appenderList) {
    a.close();
  }
  appenderList.clear();
}

代码示例来源:origin: org.ops4j.pax.logging/pax-logging-service

public synchronized void close()
{
  for (Iterator it = appenders.values().iterator(); it.hasNext();)
  {
    Node node = (Node) it.next();
    node.appender.close();
  }
  appenders.clear();
}

代码示例来源:origin: velocity/velocity-dep

/** Close all destinations*/
  public void shutdown()
  {
    Enumeration appenders = logger.getAllAppenders();
    while (appenders.hasMoreElements())
    {
      Appender appender = (Appender)appenders.nextElement();
      appender.close();
    }
  }
}

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-essentials

@Override
public void close() {
  for (Appender appender : getAppenderCollection())
    appender.close();
}

代码示例来源:origin: com.linkedin.azkaban/azkaban

private void closeLogger() {
  if (jobAppender != null) {
    logger.removeAppender(jobAppender);
    jobAppender.close();
  }
}

代码示例来源:origin: org.perf4j/perf4j

public void close() {
  //close any downstream appenders
  synchronized (downstreamAppenders) {
    flush();
    for (Enumeration enumer = downstreamAppenders.getAllAppenders();
       enumer != null && enumer.hasMoreElements();) {
      Appender appender = (Appender) enumer.nextElement();
      appender.close();
    }
  }
}

代码示例来源:origin: pentaho/big-data-plugin

public static void removeAppenderFrom( Appender appender, Map<String, Level> logLevelCache, String... logNames ) {
 for ( String logName : logNames ) {
  Logger logger = findLogger( logName );
  logger.removeAppender( appender );
  // Reset logger level if it was changed
  if ( logLevelCache.containsKey( logger.getName() ) ) {
   logger.setLevel( logLevelCache.get( logger.getName() ) );
   logLevelCache.remove( logger.getName() );
  }
 }
 appender.close();
}

代码示例来源:origin: com.linkedin.azkaban/azkaban

private void closeLogger() {
  if (logger != null) {
    logger.removeAppender(flowAppender);
    flowAppender.close();
    
    try {
      executorLoader.uploadLogFile(execId, "", 0, logFile);
    } catch (ExecutorManagerException e) {
      e.printStackTrace();
    }
  }
}

相关文章