本文整理匯總了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();
}