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


Java Category.getAllAppenders方法代碼示例

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


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

示例1: setup

import org.apache.log4j.Category; //導入方法依賴的package包/類
@BeforeClass
public static void setup() throws Exception
{
  logger.debug("Logger repository before LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
  LoggerUtil.changeLoggersLevel(Maps.<String, String>newHashMap());
  logger.debug("Logger repository after LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
  log4jLogger.setLevel(Level.TRACE);
  Category category = log4jLogger;
  while (category != null) {
    Enumeration appenders = category.getAllAppenders();
    while (appenders.hasMoreElements()) {
      Object o = appenders.nextElement();
      if (o instanceof AppenderSkeleton) {
        AppenderSkeleton appender = (AppenderSkeleton)o;
        if (!appenderLevelMap.containsKey(appender)) {
          appenderLevelMap.put(appender, appender.getThreshold());
          appender.setThreshold(Level.INFO);
        }
      }
    }
    if (category.getAdditivity()) {
      category = category.getParent();
    } else {
      category = null;
    }
  }
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:28,代碼來源:LoggerUtilTest.java

示例2: printOptions

import org.apache.log4j.Category; //導入方法依賴的package包/類
protected
void printOptions(PrintWriter out, Category cat) {
  Enumeration appenders = cat.getAllAppenders();
  Level prio = cat.getLevel();
  String appenderString = (prio == null ? "" : prio.toString());
  
  while (appenders.hasMoreElements()) {
    Appender app = (Appender) appenders.nextElement();
    String name;
    
    if ((name = (String) appenderNames.get(app)) == null) {
    
      // first assign name to the appender
      if ((name = app.getName()) == null || isGenAppName(name)) {
          name = genAppName();
      }
      appenderNames.put(app, name);
      
      printOptions(out, app, "log4j.appender."+name);
      if (app.getLayout() != null) {
        printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
      }
    }
    appenderString += ", " + name;
  }
  String catKey = (cat == Logger.getRootLogger())
      ? "log4j.rootLogger"
      : "log4j.logger." + cat.getName();
  if (appenderString != "") {
    out.println(catKey + "=" + appenderString);
  }
  if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
  	out.println("log4j.additivity." + cat.getName() + "=false");    
  }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:36,代碼來源:PropertyPrinter.java

示例3: printOptions

import org.apache.log4j.Category; //導入方法依賴的package包/類
/**
 * @since 1.2.15
 */
protected
void printOptions(PrintWriter out, Category cat) {
  Enumeration appenders = cat.getAllAppenders();
  Level prio = cat.getLevel();
  String appenderString = (prio == null ? "" : prio.toString());
  
  while (appenders.hasMoreElements()) {
    Appender app = (Appender) appenders.nextElement();
    String name;
    
    if ((name = (String) appenderNames.get(app)) == null) {
    
      // first assign name to the appender
      if ((name = app.getName()) == null || isGenAppName(name)) {
          name = genAppName();
      }
      appenderNames.put(app, name);
      
      printOptions(out, app, "log4j.appender."+name);
      if (app.getLayout() != null) {
        printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
      }
    }
    appenderString += ", " + name;
  }
  String catKey = (cat == Logger.getRootLogger())
      ? "log4j.rootLogger"
      : "log4j.logger." + cat.getName();
  if (appenderString != "") {
    out.println(catKey + "=" + appenderString);
  }
  if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
  	out.println("log4j.additivity." + cat.getName() + "=false");    
  }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:39,代碼來源:PropertyPrinter.java

示例4: RemoteLoggingConfigurator

import org.apache.log4j.Category; //導入方法依賴的package包/類
/**
 * Constructor - when created try to find if a DB appender has been configured on the local system
 */
@SuppressWarnings( "unchecked")
public RemoteLoggingConfigurator( String atsAgent ) {

    /*
     * This code is run on:
     *  - Test Executor side prior to calling an agent for first time in this testcase
     *  - Agent side prior to calling another chained agent for first time in this testcase 
     * 
     * we use this code to remember the logging configuration which we will pass to some agent
     */

    this.atsAgent = atsAgent;

    // look for the DB appender
    Category log = Logger.getLogger("com.axway.ats");
    boolean dbAppenderIsProcessed = false;
    while (log != null && !dbAppenderIsProcessed) {

        Enumeration<Appender> appenders = log.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = appenders.nextElement();

            if (appender.getClass() == ActiveDbAppender.class // running on Test Executor side
                || appender.getClass() == PassiveDbAppender.class // running on Agent side 
            ) {
                //we found the appender, read all properties
                appenderConfiguration = ((AbstractDbAppender) appender).getAppenderConfig();
                appenderLogger = log.getName();

                int atsDbLogLevel = DEFAULT_LOG_LEVEL;
                if (atsDbLoggerLevelsFromTests.containsKey(this.atsAgent)) {
                    // user specified in the test the log level for this agent
                    atsDbLogLevel = atsDbLoggerLevelsFromTests.get(this.atsAgent).toInt();
                } else if (log.getLevel() != null) {
                    // user specified the log level in log4j configuration file
                    atsDbLogLevel = log.getLevel().toInt();

                }

                //set the effective logging level for threshold if new one is set
                if (appenderConfiguration.getLoggingThreshold() == null
                    || appenderConfiguration.getLoggingThreshold().toInt() != atsDbLogLevel) {

                    /*
                     * Log4j is deprecating the Priority class used by setLoggingThreshold,
                     * but we cannot make an instance of this class as its constructor is not public.
                     * 
                     * So here we first change the log level on the Test Executor,
                     * then get the Priority object, then restore back the value on the Test Executor
                     */
                    final Level currentLevelBackup = log.getLevel();
                    log.setLevel(Level.toLevel(atsDbLogLevel));
                    appenderConfiguration.setLoggingThreshold(log.getEffectiveLevel());
                    log.setLevel(currentLevelBackup);
                }

                //exit the loop
                dbAppenderIsProcessed = true;
                break;
            }
        }

        log = log.getParent();
    }

    // look for any user loggers
    Enumeration<Logger> allLoggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
    while (allLoggers.hasMoreElements()) {
        Logger logger = allLoggers.nextElement();

        Level level = logger.getLevel();
        if (level != null) {
            // user explicitly specified a level for this logger
            otherLoggerLevels.put(logger.getName(), level.toInt());
        }
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:81,代碼來源:RemoteLoggingConfigurator.java


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