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


Java Logger.getLevel方法代碼示例

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


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

示例1: load

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
@PreAuthorize("checkPermission('ApplicationConfig')")
public SimpleEditInterface load(SessionContext context, Session hibSession) {
	List<ListItem> levels = new ArrayList<ListItem>();
	levels.add(new ListItem(String.valueOf(Level.ALL_INT), MESSAGES.levelAll()));
	levels.add(new ListItem(String.valueOf(Level.TRACE_INT), MESSAGES.levelTrace()));
	levels.add(new ListItem(String.valueOf(Level.DEBUG_INT), MESSAGES.levelDebug()));
	levels.add(new ListItem(String.valueOf(Level.INFO_INT), MESSAGES.levelInfo()));
	levels.add(new ListItem(String.valueOf(Level.WARN_INT), MESSAGES.levelWarning()));
	levels.add(new ListItem(String.valueOf(Level.ERROR_INT), MESSAGES.levelError()));
	levels.add(new ListItem(String.valueOf(Level.FATAL_INT), MESSAGES.levelFatal()));
	levels.add(new ListItem(String.valueOf(Level.OFF_INT), MESSAGES.levelOff()));
	
	SimpleEditInterface data = new SimpleEditInterface(
			new Field(MESSAGES.fieldLogger(), FieldType.text, 400, 1024, Flag.UNIQUE),
			new Field(MESSAGES.fieldLevel(), FieldType.list, 100, levels, Flag.NOT_EMPTY));
	data.setSortBy(0, 1);
	
	long id = 0;
	SimpleEditInterface.Record root = data.addRecord(id++, false);
	root.setField(0, " root", false);
	root.setField(1, String.valueOf(LogManager.getRootLogger().getLevel().toInt()));
	
	for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements(); ) {
		Logger logger = (Logger)e.nextElement();
		if (logger.getLevel() == null) continue;
		ApplicationConfig config = ApplicationConfig.getConfig("log4j.logger." + logger.getName());
		SimpleEditInterface.Record record = data.addRecord(id++, ApplicationProperties.getDefaultProperties().getProperty("log4j.logger." + logger.getName()) == null && config != null);
		record.setField(0, logger.getName(), false);
		record.setField(1, String.valueOf(logger.getLevel().toInt()));
	}

	data.setEditable(context.hasPermission(Right.ApplicationConfig));
	return data;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:36,代碼來源:Loggers.java

示例2: getLevel

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
public String getLevel(String loggerName) {
    checkNotNull(loggerName, "loggerName");
    Logger logger = LogManager.getLogger(loggerName);
    return logger == null || logger.getLevel() == null ? null : logger.getLevel().toString();
}
 
開發者ID:vy,項目名稱:hrrs,代碼行數:7,代碼來源:Log4jLoggerLevelAccessor.java

示例3: RemoteLoggingConfigurator

import org.apache.log4j.Logger; //導入方法依賴的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

示例4: needsApplying

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
@SuppressWarnings( "unchecked")
public boolean needsApplying() {

    /*
     * This code is run on remote agent's side
     */

    final String caller = ThreadsPerCaller.getCaller();

    needsToConfigureDbAppender = false;
    if (appenderConfiguration != null) {
        PassiveDbAppender dbAppender = PassiveDbAppender.getCurrentInstance(caller);
        if (dbAppender == null || !dbAppender.getAppenderConfig().equals(appenderConfiguration)) {
            // we did not have a DB appender
            // or the DB appender configuration is changed
            needsToConfigureDbAppender = true;
        }
    }

    needsToConfigureUserLoggers = false;
    for (Entry<String, Integer> userLogger : otherLoggerLevels.entrySet()) {
        Enumeration<Logger> allLoggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();

        boolean loggerAlreadyExists = false;
        boolean loggerLevelIsDifferent = false;
        while (allLoggers.hasMoreElements()) {
            Logger logger = allLoggers.nextElement();

            if (logger.getName().equals(userLogger.getKey())) {
                // this logger is already available, check its level
                loggerAlreadyExists = true;

                if (logger.getLevel() == null
                    || logger.getLevel().toInt() != userLogger.getValue()) {
                    // logger level is not set or it is not correct
                    loggerLevelIsDifferent = true;
                }

                break;
            }
        }

        if (!loggerAlreadyExists || loggerLevelIsDifferent) {
            // there is at lease one logger that must be reconfigured
            needsToConfigureUserLoggers = true;
            break;
        }
    }

    return needsToConfigureDbAppender || needsToConfigureUserLoggers;
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:53,代碼來源:RemoteLoggingConfigurator.java


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