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


Java Configuration類代碼示例

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


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

示例1: changeLogLevel

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的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: toggleCleanLogging

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的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

示例3: createLayout

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
/**
 * Creates the layout.
 *
 * @param locationInfo the location info
 * @param singleLine the single line
 * @param htmlSafe the html safe
 * @param plainContextMap the plain context map
 * @param charset the charset
 * @param userFields the user fields
 * @return the JSON log 4 j 2 layout
 */
@PluginFactory
public static JSONLog4j2Layout createLayout(
	// @formatter:off
		@PluginConfiguration final Configuration config,
		@PluginAttribute("locationInfo") boolean locationInfo,
		@PluginAttribute("singleLine") boolean singleLine,
		@PluginAttribute("htmlSafe") boolean htmlSafe,
		@PluginAttribute("plainContextMap") boolean plainContextMap, 
		@PluginAttribute("charset") Charset charset,
		@PluginElement("UserFields") final UserField[] userFields
	// @formatter:on
	) {
	
	if(charset == null){
		charset = Charset.forName("UTF-8");
	}
	
	LOGGER.debug("Creating JSONLog4j2Layout {}",charset);
    return new JSONLog4j2Layout(locationInfo, singleLine, htmlSafe, plainContextMap, userFields, charset);
}
 
開發者ID:dubasdey,項目名稱:log4j2-jsonevent-layout,代碼行數:32,代碼來源:JSONLog4j2Layout.java

示例4: createConfiguration

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
private Configuration createConfiguration(final String name, ConfigurationBuilder<BuiltConfiguration> builder) {

        builder.setConfigurationName(name);
        /* Only internal Log4J2 messages with level ERROR will be logged */
        builder.setStatusLevel(Level.ERROR);
        /* Create appender that logs to System.out */
        AppenderComponentBuilder appenderBuilder = builder.newAppender("STDOUT", "CONSOLE")
                .addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
        /* Create pattern for log messages */
        appenderBuilder.add(builder.newLayout("PatternLayout")
                .addAttribute("pattern", "[%d{HH:mm:ss}] (%c{1}) [%level] %msg%n%throwable"));
                                         /*timestamp  logger name  level   log message & optional throwable */
        builder.add(appenderBuilder);
        /* Create logger that uses STDOUT appender */
        builder.add(builder.newLogger("JukeBot", JUKEBOT_LOG_LEVEL)
                .add(builder.newAppenderRef("STDOUT"))
                .addAttribute("additivity", false));

        /* Create root logger--messages not from the above logger will all go through this one */
        builder.add(builder.newRootLogger(LIB_LOG_LEVEL).add(builder.newAppenderRef("STDOUT")));
        return builder.build();
    }
 
開發者ID:Devoxin,項目名稱:JukeBot,代碼行數:23,代碼來源:Log4JConfig.java

示例5: ExtendedJsonLayout

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
protected ExtendedJsonLayout(final Configuration config, final boolean locationInfo, final boolean properties,
          final boolean encodeThreadContextAsList,
          final boolean complete, final boolean compact, final boolean eventEol, final String headerPattern,
          final String footerPattern, final Charset charset, final boolean includeStacktrace, final String jsonExtenderClass) {
      super(config, getObjectWriter(encodeThreadContextAsList, includeStacktrace, locationInfo, properties, compact),
              charset, compact, complete, eventEol,
              PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(headerPattern).setDefaultPattern(DEFAULT_HEADER).build(),
              PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(footerPattern).setDefaultPattern(DEFAULT_FOOTER).build());
      
      Class<?> clazz;
      Object jsonAdapterobject = null;
try {
	clazz = Class.forName(jsonExtenderClass);
       Constructor<?> ctor = clazz.getConstructor();
       jsonAdapterobject = ctor.newInstance(new Object[] {});
} catch (Exception e) {
	e.printStackTrace();
}
      
      this.jsonAdapter = (ExtendedJson) jsonAdapterobject;
  }
 
開發者ID:savantly-net,項目名稱:log4j2-extended-jsonlayout,代碼行數:22,代碼來源:ExtendedJsonLayout.java

示例6: getOrCreateLoggerConfig

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的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.Configuration; //導入依賴的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.Configuration; //導入依賴的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: main

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
public static void main(String[] args) {
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
	ctx.updateLoggers(config);
	
	final CommonParam cp = ParamManager.getCommonParam("i", TIME_FRAME.MIN15, "20080101 000000", "20160101 170000");
	
	StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
	so.setInstrumentParam(cp.instrument, cp.tf);
	so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
	int num = so.setStrategyParamRange(MaPsarStrategy.class, new Integer[]{12, 500, 2}, new String[]{MA.MODE_EMA, MA.MODE_SMMA}, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.1f, 0.2f, 0.02f});
	System.out.println(num);
	so.StartOptimization();
	Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
	for (Entry<Object[],Performances> entry : entryset) {
		for (Object obj : entry.getKey()) {
			System.out.print(obj + ",\t");
		}
		System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
	}
}
 
開發者ID:zc8424,項目名稱:QuantTester,代碼行數:23,代碼來源:OptimizeMaPsar.java

示例10: main

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
public static void main(String[] args) {
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
	ctx.updateLoggers(config);
	
	final CommonParam cp = ParamManager.getCommonParam("cu", TIME_FRAME.DAY, "19980101 000000", "20160916 170000");
	
	StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
	so.setInstrumentParam(cp.instrument, cp.tf);
	so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
	int num = so.setStrategyParamRange(ChannelBreakStrategy.class, new Integer[]{4, 800, 2});
	System.out.println(num);
	so.StartOptimization();
	Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
	for (Entry<Object[],Performances> entry : entryset) {
		for (Object obj : entry.getKey()) {
			System.out.print(obj + ",\t");
		}
		System.out.println("ProfitRatio: " + entry.getValue().ProfitRatio + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
	}
}
 
開發者ID:zc8424,項目名稱:QuantTester,代碼行數:23,代碼來源:OptimizeChannelBreak.java

示例11: main

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
public static void main(String[] args) {
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
	ctx.updateLoggers(config);
	
	final CommonParam cp = ParamManager.getCommonParam("m", TIME_FRAME.MIN60, "19980101 000000", "20160101 170000");
	
	StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
	so.setInstrumentParam(cp.instrument, cp.tf);
	so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
	int num = so.setStrategyParamRange(DblMaPsarStrategy.class, new Integer[]{3, 5, 1}, new Integer[]{10, 100, 2}, MA.MA_MODES, new APPLIED_PRICE[] {APPLIED_PRICE.PRICE_CLOSE, APPLIED_PRICE.PRICE_TYPICAL}, new Float[]{0.01f, 0.02f, 0.01f}, new Float[]{0.12f, 0.2f, 0.02f});
	System.out.println(num);
	so.StartOptimization();
	Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
	for (Entry<Object[],Performances> entry : entryset) {
		for (Object obj : entry.getKey()) {
			System.out.print(obj + ",\t");
		}
		System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
	}
}
 
開發者ID:zc8424,項目名稱:QuantTester,代碼行數:23,代碼來源:OptimizeDblMaPsar.java

示例12: main

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
public static void main(String[] args) {
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	config.getLoggerConfig(strategy.Portfolio.class.getName()).setLevel(Level.WARN);
	ctx.updateLoggers(config);
	
	final CommonParam cp = ParamManager.getCommonParam("cu", TIME_FRAME.MIN15, "20080101 000000", "20160101 170000");
	
	StrategyOptimizer so = new StrategyOptimizer(tester.RealStrategyTester.class);
	so.setInstrumentParam(cp.instrument, cp.tf);
	so.setTestDateRange((int) DateTimeHelper.Ldt2Long(cp.start_date), (int) DateTimeHelper.Ldt2Long(cp.end_date));
	int num = so.setStrategyParamRange(MABreakStrategy.class, new Integer[]{8, 800, 2}, MA.MA_MODES);
	System.out.println(num);
	so.StartOptimization();
	Set<Entry<Object[],Performances>> entryset = so.result_db.entrySet();
	for (Entry<Object[],Performances> entry : entryset) {
		for (Object obj : entry.getKey()) {
			System.out.print(obj + ",\t");
		}
		System.out.println("ProfitRatio: " + String.format("%.5f", entry.getValue().ProfitRatio) + "\tMaxDrawDown: " + entry.getValue().MaxDrawDown);
	}
}
 
開發者ID:zc8424,項目名稱:QuantTester,代碼行數:23,代碼來源:OptimizeMABreak.java

示例13: checkLogEvent

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
private void checkLogEvent(Configuration config, LogEvent logEvent, String lookupTestKey, String lookupTestVal) throws IOException {
    Set<String> mdcKeys = logEvent.getContextData().toMap().keySet();
    String firstMdcKey = mdcKeys.iterator().next();
    String firstMdcKeyExcludingRegex = mdcKeys.isEmpty() ? null : String.format("^(?!%s).*$", Pattern.quote(firstMdcKey));
    List<String> ndcItems = logEvent.getContextStack().asList();
    String firstNdcItem = ndcItems.get(0);
    String firstNdcItemExcludingRegex = ndcItems.isEmpty() ? null : String.format("^(?!%s).*$", Pattern.quote(firstNdcItem));
    LogstashLayout layout = LogstashLayout
            .newBuilder()
            .setConfiguration(config)
            .setTemplateUri("classpath:LogstashTestLayout.json")
            .setStackTraceEnabled(true)
            .setLocationInfoEnabled(true)
            .setMdcKeyPattern(firstMdcKeyExcludingRegex)
            .setNdcPattern(firstNdcItemExcludingRegex)
            .build();
    String serializedLogEvent = layout.toSerializable(logEvent);
    JsonNode rootNode = OBJECT_MAPPER.readTree(serializedLogEvent);
    checkConstants(rootNode);
    checkBasicFields(logEvent, rootNode);
    checkSource(logEvent, rootNode);
    checkException(logEvent, rootNode);
    checkContextData(logEvent, firstMdcKeyExcludingRegex, rootNode);
    checkContextStack(logEvent, firstNdcItemExcludingRegex, rootNode);
    checkLookupTest(lookupTestKey, lookupTestVal, rootNode);
}
 
開發者ID:vy,項目名稱:log4j2-logstash-layout,代碼行數:27,代碼來源:LogstashLayoutTest.java

示例14: deliversToAppenderRef

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
@Test
public void deliversToAppenderRef() {

    // given
    Appender appender = mock(Appender.class);
    when(appender.isStarted()).thenReturn(true);
    Configuration configuration = mock(Configuration.class);
    String testAppenderRef = "testAppenderRef";
    when(configuration.getAppender(testAppenderRef)).thenReturn(appender);

    FailoverPolicy<String> failoverPolicy = createTestFailoverPolicy(testAppenderRef, configuration);

    String failedMessage = "test failed message";

    // when
    failoverPolicy.deliver(failedMessage);

    // then
    verify(appender, times(1)).append(any(LogEvent.class));
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:21,代碼來源:AppenderRefFailoverPolicyTest.java

示例15: resolvesAppenderRefOnlyOnce

import org.apache.logging.log4j.core.config.Configuration; //導入依賴的package包/類
@Test
public void resolvesAppenderRefOnlyOnce() {

    // given
    Appender appender = mock(Appender.class);
    when(appender.isStarted()).thenReturn(true);
    Configuration configuration = mock(Configuration.class);
    String testAppenderRef = "testAppenderRef";
    when(configuration.getAppender(testAppenderRef)).thenReturn(appender);

    FailoverPolicy<String> failoverPolicy = createTestFailoverPolicy(testAppenderRef, configuration);

    String failedMessage = "test failed message";

    // when
    failoverPolicy.deliver(failedMessage);
    failoverPolicy.deliver(failedMessage);

    // then
    verify(configuration, times(1)).getAppender(anyString());
    verify(appender, times(2)).append(any(LogEvent.class));
}
 
開發者ID:rfoltyns,項目名稱:log4j2-elasticsearch,代碼行數:23,代碼來源:AppenderRefFailoverPolicyTest.java


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