當前位置: 首頁>>代碼示例>>Java>>正文


Java LoggerConfig類代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.config.LoggerConfig的典型用法代碼示例。如果您正苦於以下問題:Java LoggerConfig類的具體用法?Java LoggerConfig怎麽用?Java LoggerConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LoggerConfig類屬於org.apache.logging.log4j.core.config包,在下文中一共展示了LoggerConfig類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: changeLogLevel

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
@PUT
@Path("/log/change-level/{loggerName}/{newLevel}")
public Response changeLogLevel(@PathParam("loggerName") String loggerName,
                               @PathParam("newLevel") String newLevel) {

    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);

    if (loggerConfig.getName().equals(LogManager.ROOT_LOGGER_NAME)) {
        return Response.ok("Not found", MediaType.TEXT_PLAIN).build();
    }

    loggerConfig.setLevel(Level.valueOf(newLevel));
    ctx.updateLoggers();  // This causes all Loggers to refetch information from their LoggerConfig.

    return Response.ok("Done", MediaType.TEXT_PLAIN).build();
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:xsharing-services-router,代碼行數:19,代碼來源:ControlResource.java

示例2: updateLoggerLevel

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
/**
 * Looks up the logger in the logger factory,
 * and attempts to find the real logger instance
 * based on the underlying logging framework
 * and retrieve the logger object. Then, updates the level.
 * This functionality at this point is heavily dependant
 * on the log4j API.
 *
 * @param loggerName  the logger name
 * @param loggerLevel the logger level
 * @param additive    the additive nature of the logger
 * @param request     the request
 * @param response    the response
 * @throws Exception the exception
 */
@PostMapping(value = "/updateLoggerLevel")
@ResponseBody
public void updateLoggerLevel(@RequestParam final String loggerName,
                              @RequestParam final String loggerLevel,
                              @RequestParam(defaultValue = "false") final boolean additive,
                              final HttpServletRequest request,
                              final HttpServletResponse response) throws Exception {
    ensureEndpointAccessIsAuthorized(request, response);

    Assert.notNull(this.loggerContext);

    final Collection<LoggerConfig> loggerConfigs = getLoggerConfigurations();
    loggerConfigs.stream().
            filter(cfg -> cfg.getName().equals(loggerName))
            .forEachOrdered(cfg -> {
                cfg.setLevel(Level.getLevel(loggerLevel));
                cfg.setAdditive(additive);
            });
    this.loggerContext.updateLoggers();
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:36,代碼來源:LoggingConfigController.java

示例3: registerParent

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
protected final void registerParent(Class<? extends BaseLog4j2Configuration> clazz){
	BaseLog4j2Configuration configuration;
	try{
		configuration = clazz.newInstance();
	}catch(InstantiationException | IllegalAccessException e){
		throw new RuntimeException(e);
	}
	for(Appender appender : configuration.getAppenders()){
		addAppender(appender);
	}
	for(LoggerConfig loggerConfig : configuration.getLoggerConfigs()){
		addLoggerConfig(loggerConfig.getName(), loggerConfig.getLevel(), loggerConfig.isAdditive(), loggerConfig
				.getAppenders().values());
	}
	for(Filter filter : configuration.getFilters()){
		addFilter(filter);
	}
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:19,代碼來源:BaseLog4j2Configuration.java

示例4: watch

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
public void watch(Class<?> loggerClass, Level level) {
    this.loggerClass = loggerClass;
    Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) {
        @Override
        public void append(LogEvent event) {
            logEvents.add(event);
        }
    };
    appender.start();
    final LoggerContext ctx = getLoggerContext();
    LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
    oldLevel = loggerConfig.getLevel();
    loggerConfig.setLevel(level);
    loggerConfig.addAppender(appender, level, null);
    ctx.updateLoggers();
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:17,代碼來源:LogTestRule.java

示例5: removeAlertListener

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
public synchronized boolean removeAlertListener(final DistributedMember member) {
  final boolean memberWasFound = this.listeners.remove(new Listener(null, member));

  if (memberWasFound) {
    if (this.listeners.size() == 0) {
      this.appenderContext.getLoggerContext().removePropertyChangeListener(this);
      this.appenderContext.getLoggerConfig().removeAppender(APPENDER_NAME);

    } else {
      LoggerConfig loggerConfig = this.appenderContext.getLoggerConfig();
      loggerConfig.addAppender(this, this.listeners.get(0).getLevel(), null);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Removed alert listener for member {}", member);
    }
  }

  return memberWasFound;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:20,代碼來源:AlertAppender.java

示例6: getOrCreateLoggerConfig

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
public static LoggerConfig getOrCreateLoggerConfig(String name) {
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  Configuration config = context.getConfiguration();
  LoggerConfig logConfig = config.getLoggerConfig(name);
  boolean update = false;
  if (!logConfig.getName().equals(name)) {
    List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
    Map<Property, Boolean> properties = logConfig.getProperties();
    Set<Property> props = properties == null ? null : properties.keySet();
    logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()),
        logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()),
        appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]),
        props == null ? null : props.toArray(new Property[props.size()]), config, null);
    config.addLogger(name, logConfig);
    update = true;
  }
  if (update) {
    context.updateLoggers();
  }
  return logConfig;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:Configurator.java

示例7: hasLoggerFilter

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
public static boolean hasLoggerFilter(final Configuration config) {
  for (LoggerConfig loggerConfig : config.getLoggers().values()) {
    boolean isRoot = loggerConfig.getName().equals("");
    boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
    boolean hasFilter = loggerConfig.hasFilter();
    boolean isGemFireVerboseFilter =
        hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString())
            || LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()));

    if (isRoot || isGemFire) {
      // check for Logger Filter
      if (hasFilter && !isGemFireVerboseFilter) {
        return true;
      }
    }
  }
  return false;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:19,代碼來源:Configurator.java

示例8: hasAppenderRefFilter

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
public static boolean hasAppenderRefFilter(final Configuration config) {
  for (LoggerConfig loggerConfig : config.getLoggers().values()) {
    boolean isRoot = loggerConfig.getName().equals("");
    boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);

    if (isRoot || isGemFire) {
      // check for AppenderRef Filter
      for (AppenderRef appenderRef : loggerConfig.getAppenderRefs()) {
        if (appenderRef.getFilter() != null) {
          return true;
        }
      }
    }
  }
  return false;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:Configurator.java

示例9: addSuspectFileAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
/**
 * Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
 * later to scan for suspect strings. The pattern of the messages conforms to the original log
 * format so that hydra will be able to parse them.
 */
private static void addSuspectFileAppender(final String workspaceDir) {
  final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();

  final LoggerContext appenderContext =
      ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME))
          .getContext();

  final PatternLayout layout = PatternLayout.createLayout(
      "[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n",
      null, null, null, Charset.defaultCharset(), true, false, "", "");

  final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false",
      DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null,
      appenderContext.getConfiguration());
  fileAppender.start();

  LoggerConfig loggerConfig =
      appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
  loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:DUnitLauncher.java

示例10: applyDelegate

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
@Override
public void applyDelegate(Config config) {
    Security.addProvider(new BouncyCastleProvider());
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration ctxConfig = ctx.getConfiguration();
    LoggerConfig loggerConfig = ctxConfig.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    if (isDebug()) {
        loggerConfig.setLevel(Level.DEBUG);
    } else if (isQuiet()) {
        loggerConfig.setLevel(Level.OFF);
    } else if (getLogLevel() != null) {
        loggerConfig.setLevel(getLogLevel());
    }
    ctx.updateLoggers();
    LOGGER.debug("Using the following security providers");
    for (Provider p : Security.getProviders()) {
        LOGGER.debug("Provider {}, version, {}", p.getName(), p.getVersion());
    }

    // remove stupid Oracle JDK security restriction (otherwise, it is not
    // possible to use strong crypto with Oracle JDK)
    UnlimitedStrengthEnabler.enable();
}
 
開發者ID:RUB-NDS,項目名稱:TLS-Attacker,代碼行數:24,代碼來源:GeneralDelegate.java

示例11: addFileAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
private static void addFileAppender() throws IOException {
  final String tempDir = System.getProperty("java.io.tmpdir");
  final File logFile = new File(tempDir, "meghanada_server.log");
  final LoggerContext context = (LoggerContext) LogManager.getContext(false);
  final Configuration configuration = context.getConfiguration();
  final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
  final FileAppender fileAppender =
      FileAppender.newBuilder()
          .withName("file")
          .withLayout(
              PatternLayout.newBuilder()
                  .withPattern("[%d][%-5.-5p][%-14.-14c{1}:%4L] %-22.-22M - %m%n")
                  .build())
          .withFileName(logFile.getCanonicalPath())
          .build();
  configuration.addAppender(fileAppender);
  loggerConfig.addAppender(fileAppender, Level.ERROR, null);
  context.updateLoggers();
}
 
開發者ID:mopemope,項目名稱:meghanada-server,代碼行數:20,代碼來源:Main.java

示例12: StandaloneLoggerConfiguration

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
/**
 * Constructor to create the default configuration.
 */
public StandaloneLoggerConfiguration(ConfigurationSource source) {
    super(source);

    setName(CONFIG_NAME);
    final Appender appender = StandaloneLogEventAppender.createAppender("StandaloneLogAppender", 1000);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ALL;
    root.setLevel(level);
}
 
開發者ID:Steve973,項目名稱:camel-standalone,代碼行數:19,代碼來源:StandaloneLoggerConfiguration.java

示例13: configureLogging

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
protected void configureLogging() {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, config, null, null,
            true, false, null, null);
    Appender appender = FileAppender.createAppender(workDir + "/logs/camel-standalone.log", "false", "false", "File", "true",
            "false", "false", "4000", layout, null, "false", null, config);
    appender.start();
    config.addAppender(appender);
    AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
    AppenderRef[] refs = new AppenderRef[] {ref};
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "StandaloneFileLoggerConfig",
            "true", refs, null, config, null );
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("StandaloneFileLoggerConfig", loggerConfig);
    ctx.updateLoggers();
}
 
開發者ID:Steve973,項目名稱:camel-standalone,代碼行數:18,代碼來源:Standalone.java

示例14: configureLog4j

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
private static Logger configureLog4j() {
    LoggerContext context = (LoggerContext) LogManager.getContext();
    Configuration config = context.getConfiguration();

    PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
    Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
    appender.start();
    AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
    AppenderRef[] refs = new AppenderRef[]{ref};
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
    loggerConfig.addAppender(appender, null, null);

    config.addAppender(appender);
    config.addLogger("Main.class", loggerConfig);
    context.updateLoggers(config);
    return LogManager.getContext().getLogger("Main.class");
}
 
開發者ID:vitaly-chibrikov,項目名稱:homework_tester,代碼行數:18,代碼來源:Main.java

示例15: testReadException

import org.apache.logging.log4j.core.config.LoggerConfig; //導入依賴的package包/類
/**
 * Tests that {@link oc.io.base.DecoupledInputStream#read()} terminates
 * normally when IOException is thrown in wrapped InputStream
 * 
 * @throws IOException
 */
@Test
public void testReadException() throws IOException {
	final byte b[] = new byte[1];

	// Temporary disable logging for avoiding annoying Exception trace
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
	final Level currentLevel = loggerConfig.getLevel();
	loggerConfig.setLevel(Level.FATAL);
	ctx.updateLoggers();

	final TestInputStream testInputStream = new TestInputStream(new IOException(
			"This exception is thrown due to a test scenario. This is expected behaviour"));
	final DecoupledInputStream decInputStream = new DecoupledInputStream(testInputStream);
	assertEquals(-1, decInputStream.read(b));
	decInputStream.close();

	loggerConfig.setLevel(currentLevel);
	ctx.updateLoggers();
}
 
開發者ID:oschuen,項目名稱:ballin-happiness,代碼行數:28,代碼來源:DecoupledInputStreamTestCase.java


注:本文中的org.apache.logging.log4j.core.config.LoggerConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。