本文整理汇总了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;
}
示例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();
}
示例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());
}
}
}
示例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;
}