本文整理汇总了Java中org.apache.logging.log4j.core.config.Configuration.getRootLogger方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getRootLogger方法的具体用法?Java Configuration.getRootLogger怎么用?Java Configuration.getRootLogger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.config.Configuration
的用法示例。
在下文中一共展示了Configuration.getRootLogger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeLogLevel
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* Auxiliary method to change the log level.
*
* @param logLevel
* The log level to set.
*
* @return
* A ResponseContext containing the result of the command.
*/
public static ResponseContext changeLogLevel(String logLevel) {
ResponseContext responseContext = new ResponseContext();
responseContext.setContentType(ResponseContext.PLAIN_TEXT_CONTENT_TYPE);
LoggerContext loggerContext = LoggerContext.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
LoggerConfig rootLogger = configuration.getRootLogger();
if (rootLogger != null) {
switch (StandardLevel.getStandardLevel(Level.toLevel(logLevel, Level.INFO).intLevel())) {
case ERROR:
rootLogger.setLevel(Level.ERROR);
responseContext.setResponse("Log level changed to ERROR");
break;
case WARN:
rootLogger.setLevel(Level.WARN);
responseContext.setResponse("Log level changed to WARN");
break;
case INFO:
rootLogger.setLevel(Level.INFO);
responseContext.setResponse("Log level changed to INFO");
break;
case DEBUG:
rootLogger.setLevel(Level.DEBUG);
responseContext.setResponse("Log level changed to DEBUG");
break;
case OFF:
rootLogger.setLevel(Level.OFF);
responseContext.setResponse("Logging switched off");
break;
default:
responseContext.setResponse("Log level unchanged, unsupported level: " + logLevel);
}
loggerContext.updateLoggers();
} else {
responseContext.setResponse("Unable to change log level, no ROOT logger found...");
responseContext.setErrorCode(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR));
}
return responseContext;
}
示例2: addRootApender
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* Adds the specified appender to the root logger.
*
* @param appender
* the appender
* @param level
* the logging level to assign to the appender. Default is INFO
*/
public static synchronized void addRootApender(Appender appender, String level) {
Configuration config = getConfiguration();
appender.start();
config.addAppender(appender);
Level l = Level.toLevel(level, Level.INFO);
LoggerConfig root = config.getRootLogger();
if (!root.getLevel().isLessSpecificThan(l)) {
if (originalRootLevel == null) {
originalRootLevel = root.getLevel();
Iterator<AppenderRef> it = root.getAppenderRefs().iterator();
while (it.hasNext()) {
AppenderRef ar = it.next();
if (ar.getLevel() == null) {
Appender a = root.getAppenders().get(ar.getRef());
root.removeAppender(a.getName());
root.addAppender(a, originalRootLevel, ar.getFilter());
}
}
}
root.setLevel(l);
}
root.addAppender(appender, l, null);
addedAppenders++;
getContext().updateLoggers();
}
示例3: removeRootApender
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* Removes the specified previously added appender from the root logger.
*
* @param appender
* the appender to remove
*/
public static synchronized void removeRootApender(Appender appender) {
if (addedAppenders > 0) {
Configuration config = getConfiguration();
String name = appender.getName();
LoggerConfig root = config.getRootLogger();
root.removeAppender(name);
appender.stop();
if (--addedAppenders == 0 && originalRootLevel != null) {
root.setLevel(originalRootLevel);
}
getContext().updateLoggers();
}
}
示例4: getRootLogger
import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
* Auxiliary method to find the root logger.
*
* @return
* A reference of the root logger.
*/
private LoggerConfig getRootLogger() {
LoggerContext loggerContext = LoggerContext.getContext(false);
Configuration configuration = loggerContext.getConfiguration();
return configuration.getRootLogger();
}