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


Java LogManager.getContext方法代码示例

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


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

示例1: changeLogLevel

import org.apache.logging.log4j.LogManager; //导入方法依赖的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: main

import org.apache.logging.log4j.LogManager; //导入方法依赖的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

示例3: toggleCleanLogging

import org.apache.logging.log4j.LogManager; //导入方法依赖的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

示例4: getOrCreateLoggerConfig

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
public static LoggerConfig getOrCreateLoggerConfig(String name, boolean additive,
    boolean forceAdditivity) {
  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(additive), 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 (forceAdditivity && logConfig.isAdditive() != additive) {
    logConfig.setAdditive(additive);
    update = true;
  }
  if (update) {
    context.updateLoggers();
  }
  return logConfig;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:27,代码来源:Configurator.java

示例5: onApplicationEvent

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(final ContextClosedEvent event) {
    logger.info("Gracefully shutting down application.");
    manager.stop();
    try {
        manager.tearDown();
        logger.info("JOAL gracefully shut down.");
    } catch (final IOException e) {
        logger.error("Failed to gracefully shut down JOAL.", e);
    }

    // Since we disabled log4j2 shutdown hook, we need to handle it manually.
    final LifeCycle loggerContext = (LoggerContext) LogManager.getContext(false);
    loggerContext.stop();
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:16,代码来源:ApplicationClosingListener.java

示例6: getContext

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
/**
 * Gets the {@link LoggerContext} associated with the given caller class.
 *
 * @param callerClass the caller class
 * @return the LoggerContext for the calling class
 */
protected LoggerContext getContext(final Class<?> callerClass) {
    ClassLoader cl = null;
    if (callerClass != null) {
        cl = callerClass.getClassLoader();
    }
    if (cl == null) {
        cl = LoaderUtil.getThreadContextClassLoader();
    }
    return LogManager.getContext(cl, false);
}
 
开发者ID:battlesteed,项目名称:hibernateMaster,代码行数:17,代码来源:Log4jLoggerFactory.java

示例7: main

import org.apache.logging.log4j.LogManager; //导入方法依赖的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("ru", TIME_FRAME.DAY, "20100101 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(AlligatorDivergent.class,
			new Float[]{0.01f, 0.01f, 0.01f},
			new Float[]{0.1999f, 0.1999f, 0.01f},
			new Integer[]{4, 10, 1},
			new Float[]{1.0f, 3.0f, 0.5f},
			new Float[]{10.0f, 1100.0f, 5.0f});
	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,代码行数:28,代码来源:OptimizeAlligatorDivergent.java

示例8: main

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
public static void main(String [] args){
	try{
		System.out.println(logger1.isDebugEnabled());
		System.out.println(logger1.isErrorEnabled());
		System.out.println(logger1.isInfoEnabled());

		System.out.println(logger2.isDebugEnabled());
		System.out.println(logger2.isErrorEnabled());
		System.out.println(logger2.isInfoEnabled());

		System.out.println(logger3.isDebugEnabled());
		System.out.println(logger3.isErrorEnabled());
		System.out.println(logger3.isInfoEnabled());

		System.out.println(logger4.isDebugEnabled());
		System.out.println(logger4.isErrorEnabled());
		System.out.println(logger4.isInfoEnabled());

		org.apache.logging.log4j.spi.LoggerContext context=LogManager.getContext();
		Logger logger = (Logger) LogManager.getLogger();
		LoggerConfig config=logger.get();
		Map<Property, Boolean> properties=config.getProperties();
		System.out.println(config.getName());
		LoggerContext ctx=LoggerContext.getContext();
		Object appenders=ctx.getConfiguration().getAppenders();
		System.out.println(appenders.toString());
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		System.exit(0);
	}


}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:35,代码来源:TestLog4j2.java

示例9: setLevel

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
public static void setLevel(String name, Level level) {
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  LoggerConfig logConfig = getLoggerConfig(name);

  logConfig.setLevel(level);
  context.updateLoggers();

  if (level.isLessSpecificThan(Level.DEBUG)) {
    LogService.configureFastLoggerDelegating();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:12,代码来源:Configurator.java

示例10: testLoggingLevelsFromSettings

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
public void testLoggingLevelsFromSettings() throws IOException, UserException {
    final Level rootLevel = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
    final Level fooLevel = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
    final Level barLevel = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
    final Path configDir = getDataPath("minimal");
    final Settings settings = Settings.builder()
        .put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath())
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .put("logger.level", rootLevel.name())
        .put("logger.foo", fooLevel.name())
        .put("logger.bar", barLevel.name())
        .build();
    final Environment environment = new Environment(settings);
    LogConfigurator.configure(environment);

    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final Map<String, LoggerConfig> loggerConfigs = config.getLoggers();
    assertThat(loggerConfigs.size(), equalTo(3));
    assertThat(loggerConfigs, hasKey(""));
    assertThat(loggerConfigs.get("").getLevel(), equalTo(rootLevel));
    assertThat(loggerConfigs, hasKey("foo"));
    assertThat(loggerConfigs.get("foo").getLevel(), equalTo(fooLevel));
    assertThat(loggerConfigs, hasKey("bar"));
    assertThat(loggerConfigs.get("bar").getLevel(), equalTo(barLevel));

    assertThat(ctx.getLogger(randomAsciiOfLength(16)).getLevel(), equalTo(rootLevel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:EvilLoggerConfigurationTests.java

示例11: configureLogMetrics

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
private static void configureLogMetrics() {
  InstrumentedAppender appender = InstrumentedAppender.createAppender("PROMETHEUS");
  appender.start();
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  Configuration config = context.getConfiguration();
  config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, null, null);
  context.updateLoggers(config);
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:9,代码来源:MonitoringModule.java

示例12: configure

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException {
    Objects.requireNonNull(settings);
    Objects.requireNonNull(configsPath);
    Objects.requireNonNull(logsPath);

    setLogConfigurationSystemProperty(logsPath, settings);
    // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
    configureStatusLogger();

    final LoggerContext context = (LoggerContext) LogManager.getContext(false);

    final List<AbstractConfiguration> configurations = new ArrayList<>();
    final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
    final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals("log4j2.properties")) {
                configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri()));
            }
            return FileVisitResult.CONTINUE;
        }
    });

    if (configurations.isEmpty()) {
        throw new UserException(
                ExitCodes.CONFIG,
                "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories");
    }

    context.start(new CompositeConfiguration(configurations));

    configureLoggerLevels(settings);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:LogConfigurator.java

示例13: activateSilent

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
/**
 * Activates the app silent mode.
 */
private static void activateSilent() {
  LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
  loggerConfig.setLevel(Level.OFF);
  ctx.updateLoggers();
}
 
开发者ID:braineering,项目名称:ares,代码行数:10,代码来源:CliService.java

示例14: setLogLevel

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
/**
 * Set the log level for the logger.
 * Method is used in js script.
 *
 * @param p_logLevel
 *         Log level to set.
 */
@SuppressWarnings("WeakerAccess")
public static void setLogLevel(final Level p_logLevel) {

    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(p_logLevel);
    // This causes all Loggers to refetch information from their LoggerConfig
    ctx.updateLoggers();
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:18,代码来源:LoggerService.java

示例15: test_serialized_event

import org.apache.logging.log4j.LogManager; //导入方法依赖的package包/类
@Test
public void test_serialized_event() throws IOException {
    String lookupTestKey = "lookup_test_key";
    String lookupTestVal = String.format("lookup_test_value_%d", (int) (1000 * Math.random()));
    System.setProperty(lookupTestKey, lookupTestVal);
    LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    Configuration loggerConfig = loggerContext.getConfiguration();
    for (LogEvent logEvent : LogEventFixture.LOG_EVENTS) {
        checkLogEvent(loggerConfig, logEvent, lookupTestKey, lookupTestVal);
    }
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:12,代码来源:LogstashLayoutTest.java


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