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