本文整理匯總了Java中org.apache.logging.log4j.core.config.LoggerConfig.removeAppender方法的典型用法代碼示例。如果您正苦於以下問題:Java LoggerConfig.removeAppender方法的具體用法?Java LoggerConfig.removeAppender怎麽用?Java LoggerConfig.removeAppender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.config.LoggerConfig
的用法示例。
在下文中一共展示了LoggerConfig.removeAppender方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateAppenders
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
private void updateAppenders(LoggerConfig loggerConfig, Iterable<String> appendersRef){
Map<String,Appender> appenders = loggerConfig.getAppenders();
for(String string : appenders.keySet()){
loggerConfig.removeAppender(string);
}
for(String appenderRef : appendersRef){
Appender appender = config.getAppender(appenderRef);
if(appender != null){
loggerConfig.addAppender(appender, null, null);
}else{
logger.error("Appender \"" + appenderRef + "\" not found");
}
}
}
示例2: after
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
@Override
protected void after() {
if (loggerClass == null) {
return;
}
final LoggerContext ctx = getLoggerContext();
LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
loggerConfig.setLevel(oldLevel);
loggerConfig.removeAppender(APPENDER_NAME);
ctx.updateLoggers();
}
示例3: removeConsoleAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
/**
* Removes STDOUT ConsoleAppender from ROOT logger. Only called when using the log4j2-default.xml
* configuration. This is done when creating the LogWriterAppender for log-file. The Appender
* instance is stored in stdoutAppender so it can be restored later using restoreConsoleAppender.
*/
public static synchronized void removeConsoleAppender() {
final AppenderContext appenderContext =
LogService.getAppenderContext(LogService.ROOT_LOGGER_NAME);
final LoggerConfig config = appenderContext.getLoggerConfig();
Appender stdout = config.getAppenders().get(STDOUT);
if (stdout != null) {
config.removeAppender(STDOUT);
stdoutAppender = stdout;
appenderContext.getLoggerContext().updateLoggers();
}
}
示例4: removeAppender
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
private void removeAppender(String name) {
final LoggerContext context = LoggerContext.getContext(false);
final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.removeAppender(name);
}
config.getRootLogger().removeAppender(name);
context.updateLoggers();
}
示例5: deregister
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
void deregister() {
if (LogManager.getContext(false) instanceof LoggerContext) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
if (ctx.getConfiguration() instanceof AbstractConfiguration) {
final AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
final Appender appender = getSingleton();
appender.stop();
config.removeAppender(appender.getName());
final Logger rootLogger = LogManager.getRootLogger();
final LoggerConfig loggerConfig = config.getLoggerConfig(rootLogger.getName());
loggerConfig.removeAppender(appender.getName());
ctx.updateLoggers();
}
}
}
示例6: setThreshold
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的package包/類
@Override
public void setThreshold(String level) {
Log4j2Appender app = getAppender();
Level current = app.getThreshold();
app.setThreshold(Level.toLevel(level));
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
LoggerConfig config = getLoggerConfig(ctx, LoggerInfo.ROOT_NAME);
config.removeAppender(app.getName());
config.addAppender(app, app.getThreshold(), app.getFilter());
((LoggerContext)LogManager.getContext(false)).updateLoggers();
watcherLog.info("Updated watcher threshold from "+current+" to " + level);
}
示例7: addRootApender
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的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();
}
示例8: removeRootApender
import org.apache.logging.log4j.core.config.LoggerConfig; //導入方法依賴的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();
}
}