当前位置: 首页>>代码示例>>Java>>正文


Java LoggerContext.getLoggers方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.LoggerContext.getLoggers方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.getLoggers方法的具体用法?Java LoggerContext.getLoggers怎么用?Java LoggerContext.getLoggers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.LoggerContext的用法示例。


在下文中一共展示了LoggerContext.getLoggers方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toggleCleanLogging

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private void toggleCleanLogging() {
	
	this.cleanLogging = !cleanLogging;
	interactionHandler.sendText("clean logging: " + cleanLogging);
	String appenderToAdd = cleanLogging ? "Clean" : "Console";
	String appenderToRemove = cleanLogging ? "Console" : "Clean";
	
       final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
       final Configuration config = ctx.getConfiguration();
       
       for (org.apache.logging.log4j.core.Logger logger : ctx.getLoggers()) {
       	
       	logger.removeAppender(config.getAppender(appenderToRemove));
       	config.addLoggerAppender(logger, config.getAppender(appenderToAdd));
       }
       ctx.updateLoggers();
	
}
 
开发者ID:OpenBW,项目名称:TSBW4J,代码行数:19,代码来源:Bot.java

示例2: getLogLevels

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@POST
@Path("/getLevels")
@Produces("application/json")
public JsonLogLevels getLogLevels() {
    List<JsonLogLevel> logLevels = new ArrayList<>();

    Logger rootLogger = LogManager.getRootLogger();
    if (rootLogger instanceof org.apache.logging.log4j.core.Logger) {
        LoggerContext lc = ((org.apache.logging.log4j.core.Logger) rootLogger).getContext();
        Collection<org.apache.logging.log4j.core.Logger> loggers = lc.getLoggers();
        for (Logger logger : loggers) {
            addToLogLevels(logger, logLevels);
        }
    } else {
        LOG.warn("Cannot get log level because root logger is not an instance of org.apache.logging.log4j.core.Logger");
    }
    addToLogLevels(rootLogger, logLevels);
    return new JsonLogLevels(logLevels);
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:20,代码来源:LogLevelRestEndpoints.java

示例3: loggerajax

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public Response loggerajax(Request request) {
    Map<String, Object> body = request.getBodyAsJsonMap();
    if (body != null && body.size() > 0) {
        String clazz = body.get("class").toString();
        String level = body.get("level").toString();
        if (StringUtils.isNotBlank(clazz) && StringUtils.isNotBlank(level)) {
            LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
            for (Logger logger : loggerContext.getLoggers()) { //NOSONAR
                if (clazz.equals(logger.getName())) {
                    logger.setLevel(Level.getLevel(level));
                    break;
                }
            }
        }
    }
    
    return Response.withOk().andEmptyBody();
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:19,代码来源:AdminController.java

示例4: getLoggers

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * Get all loggers that are available.
 * @param filter a string that must be contained in the class name for the LOGGER to be added to the result
 * @return a list with LoggingLevelBean objects
 */
public static List<LoggingLevelBean> getLoggers(String filter){
	List<LoggingLevelBean> loggers = new ArrayList<LoggingLevelBean>(100);
	LoggingLevelBean llb = null;
	final LoggerContext ctx = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(StartServlet.class.getClassLoader(), false);
       
       Collection<org.apache.logging.log4j.core.Logger> cloggers = ctx.getLoggers();
       
	if (filter != null) {
		filter = filter.toUpperCase();
	}

	for (org.apache.logging.log4j.core.Logger currentLogger: cloggers) {
		llb = new LoggingLevelBean(currentLogger.getName(), currentLogger.getLevel().name(),currentLogger.getLevel().intLevel());
		if (filter == null || "".equals(filter)) {
			loggers.add(llb);
		} else if (filter!= null && llb.getClassName().toUpperCase().contains(filter)) {
			loggers.add(llb);
		}
	}
	Collections.sort(loggers);
	return loggers;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:28,代码来源:LoggingConfigBL.java

示例5: updateLoggingSeverity

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
    String loggingLevel = appConfiguration.getLoggingLevel();
    if (StringHelper.isEmpty(loggingLevel)) {
        return;
    }

    log.info("Setting loggers level to: '{}'", loggingLevel);

    LoggerContext loggerContext = LoggerContext.getContext(false);

    if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
        log.info("Reloadming log4j configuration");
        loggerContext.reconfigure();
        return;
    }

    Level level = Level.toLevel(loggingLevel, Level.INFO);

    for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
        String loggerName = logger.getName();
        if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu")) {
            logger.setLevel(level);
        }
    }
}
 
开发者ID:GluuFederation,项目名称:oxTrust,代码行数:26,代码来源:AppInitializer.java

示例6: updateLoggingSeverity

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
	String loggingLevel = appConfiguration.getLoggingLevel();
	if (StringHelper.isEmpty(loggingLevel)) {
		return;
	}

	log.info("Setting loggers level to: '{}'", loggingLevel);
	
	LoggerContext loggerContext = LoggerContext.getContext(false);

	if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
		log.info("Reloading log4j configuration");
		loggerContext.reconfigure();
		return;
	}

	Level level = Level.toLevel(loggingLevel, Level.INFO);

	for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
		String loggerName = logger.getName();
		if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu") || level == Level.OFF) {
			logger.setLevel(level);
		}
	}
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:26,代码来源:AppInitializer.java

示例7: flushAll

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
public static void flushAll() {
	final LoggerContext logCtx = ((LoggerContext) LogManager.getContext());
	for(final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) {
		for(final Appender appender : logger.getAppenders().values()) {
			if(appender instanceof AbstractOutputStreamAppender) {
				((AbstractOutputStreamAppender) appender).getManager().flush();
			}
		}
	}
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:11,代码来源:LogUtil.java

示例8: getAllLoggers

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Override
public Collection<LoggerInfo> getAllLoggers() {
  Logger root = LogManager.getRootLogger();
  Map<String,LoggerInfo> map = new HashMap<String,LoggerInfo>();

  LoggerContext ctx = (LoggerContext)LogManager.getContext(false);
  for (org.apache.logging.log4j.core.Logger logger : ctx.getLoggers()) {
    String name = logger.getName();
    if (logger == root || root.equals(logger) || isRootLogger(name))
      continue;

    map.put(name, new Log4j2Info(name, logger));

    while (true) {
      int dot = name.lastIndexOf(".");
      if (dot < 0)
        break;

      name = name.substring(0, dot);
      if (!map.containsKey(name))
        map.put(name, new Log4j2Info(name, null));
    }
  }

  map.put(LoggerInfo.ROOT_NAME, new Log4j2Info(LoggerInfo.ROOT_NAME, root));

  return map.values();
}
 
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:29,代码来源:Log4j2Watcher.java

示例9: logLevels

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@GET
@Path("/logLevels/{instanceKey}")
public Response logLevels(@PathParam("instanceKey") @DefaultValue("") String instanceKey) {
    try {
        HtmlCanvas canvas = new HtmlCanvas();

        canvas.form(HtmlAttributesFactory
            .action("/ui/deployable/setLogLevel/" + instanceKey)
            .method("post")
            .id("setLogLevel-form"));
        canvas.fieldset();

        org.apache.logging.log4j.Logger rl = LogManager.getRootLogger();
        if (rl instanceof Logger) {
            LoggerContext rlContext = ((Logger) rl).getContext();
            Collection<Logger> loggers = rlContext.getLoggers();

            canvas.select(HtmlAttributesFactory.name("logger"));
            for (Logger logger : loggers) {
                try {
                    Class.forName(logger.getName());
                    String level = (logger.getLevel() == null) ? null : logger.getLevel().toString();
                    canvas.option(HtmlAttributesFactory.value(logger.getName())).content(level + "=" + logger.getName());
                } catch (ClassNotFoundException e) {
                    LOG.warn("Failed to find class:{}", e.getLocalizedMessage());
                }
            }
            canvas._select();
        } else {
            canvas.h1().content("Loggers unavailable, RootLogger is: " + rl.getClass().getName() + " expected: " + Logger.class.getName());
        }

        canvas.select(HtmlAttributesFactory.name("level"));
        canvas.option(HtmlAttributesFactory.value("")).content("Inherit");
        canvas.option(HtmlAttributesFactory.value("TRACE")).content("TRACE");
        canvas.option(HtmlAttributesFactory.value("DEBUG")).content("DEBUG");
        canvas.option(HtmlAttributesFactory.value("INFO")).content("INFO");
        canvas.option(HtmlAttributesFactory.value("WARN")).content("WARN");
        canvas.option(HtmlAttributesFactory.value("ERROR")).content("ERROR");
        canvas.option(HtmlAttributesFactory.value("OFF")).content("OFF");
        canvas._select();

        canvas.input(HtmlAttributesFactory.type("submit").value("Change"))
            ._fieldset()
            ._form();

        return Response.ok(canvas.toHtml(), MediaType.TEXT_HTML).build();
    } catch (Exception x) {
        LOG.warn("Failed to set logging level.", x);
        return ResponseHelper.INSTANCE.errorResponse("Failed to set logging level.", x);
    }
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:53,代码来源:RestfulBaseEndpoints.java


注:本文中的org.apache.logging.log4j.core.LoggerContext.getLoggers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。