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


Java LoggerContext类代码示例

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


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

示例1: changeLogLevel

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

示例3: start

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
@Setup
public void start() {
    counter = 0;
    if (log == null) {
        System.setProperty(
                "Log4jContextSelector",
                "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
        LoggerContext context = LoggerContext.getContext();
        log = context.getLogger("Log4j2");
        log.setAdditive(false);
        ArrayList<Appender> list = new ArrayList<Appender>();
        list.addAll(log.getAppenders().values());
        for (Appender a : list) {
            log.removeAppender(a);
        }
    }
}
 
开发者ID:a-hansen,项目名称:alog,代码行数:18,代码来源:AlogBenchmark.java

示例4: buildLoggerContext

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
/**
 * Build logger context logger context.
 *
 * @param environment    the environment
 * @param resourceLoader the resource loader
 * @return the logger context
 */
public static Pair<Resource, LoggerContext> buildLoggerContext(final Environment environment, final ResourceLoader resourceLoader) {
    try {
        final String logFile = environment.getProperty("logging.config", "classpath:/log4j2.xml");
        LOGGER.debug("Located logging configuration reference in the environment as [{}]", logFile);

        if (ResourceUtils.doesResourceExist(logFile, resourceLoader)) {
            final Resource logConfigurationFile = resourceLoader.getResource(logFile);
            LOGGER.debug("Loaded logging configuration resource [{}]. Initializing logger context...", logConfigurationFile);
            final LoggerContext loggerContext = Configurator.initialize("CAS", null, logConfigurationFile.getURI());
            LOGGER.debug("Installing log configuration listener to detect changes and update");
            loggerContext.getConfiguration().addListener(reconfigurable -> loggerContext.updateLoggers(reconfigurable.reconfigure()));
            return Pair.of(logConfigurationFile, loggerContext);

        }
        LOGGER.warn("Logging configuration cannot be found in the environment settings");
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:ControllerUtils.java

示例5: watch

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

示例6: getOrCreateLoggerConfig

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的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: tearDownAfterClass

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
@AfterClass
public static void tearDownAfterClass() throws Exception {
  for (Handler handler : saveHandlers) {
    julLogger.addHandler(handler);
  }

  if (saveLog4j2Config == null) {
    System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  } else {
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, saveLog4j2Config);
    ((LoggerContext) LogManager.getContext(false)).reconfigure();
  }

  if (saveUserDir == null) {
    System.clearProperty("user.dir");
  } else {
    System.setProperty("user.dir", saveUserDir);
  }
  if (saveUserHome == null) {
    System.clearProperty("user.home");
  } else {
    System.setProperty("user.home", saveUserHome);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:GfshInitFileJUnitTest.java

示例8: addSuspectFileAppender

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

示例9: main

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的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.LoggerContext; //导入依赖的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.LoggerContext; //导入依赖的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.LoggerContext; //导入依赖的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: getActiveLogFilePaths

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
/**
 * We cannot presume that the default file name/location setting won't be changed by the user.
 * Therefore, we should be able to retrieve that info from the underlying logging mechanism
 * by iterating over appenders.
 */
private List<Path> getActiveLogFilePaths() {
    LoggerContextFactory factory = LogManager.getFactory();
    ContextSelector selector = ((Log4jContextFactory) factory).getSelector();

    List<Path> fileNameList = new ArrayList<>();
    for (LoggerContext ctx : selector.getLoggerContexts()) {
        for (Appender appender : ctx.getConfiguration().getAppenders().values()) {
            String fileName = extractFileName(appender);
            if (fileName != null) {
                fileNameList.add(Paths.get(fileName));
            }
        }
    }
    return fileNameList;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:21,代码来源:LogFileRetriever.java

示例14: KafkaManager

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
public KafkaManager(final LoggerContext loggerContext, final String name, final String topic, final String zkServers, final String mail, final  String rpc,
                    final String app, final String host, final Property[] properties) {
    super(loggerContext, name);
    this.topic = topic;
    this.zkServers = zkServers;
    this.mail = mail;
    this.rpc = rpc;
    this.app = app;
    this.orginApp = app;
    this.host = host;
    this.checkAndSetConfig(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());
    this.checkAndSetConfig(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    // 设置分区类, 使用自定义的KeyModPartitioner,同样的key进入相同的partition
    this.checkAndSetConfig(ProducerConfig.PARTITIONER_CLASS_CONFIG, KeyModPartitioner.class.getName());
    // xml配置里面的参数
    for (final Property property : properties) {
        this.config.put(property.getName(), property.getValue());
    }
    // 由于容器部署需要从外部获取host
    this.config.put(ProducerConfig.CLIENT_ID_CONFIG, this.app + Constants.MIDDLE_LINE + this.host + Constants.MIDDLE_LINE + "log4j2");
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:22,代码来源:KafkaManager.java

示例15: configureLoggers

import org.apache.logging.log4j.core.LoggerContext; //导入依赖的package包/类
/**
 * Setup the file logger so that it outputs messages to the appropriately named file,
 * depending on the subtitle of the current program instance.
 */
private static void configureLoggers( String subtitle )
{
	// Remove all characters that are not allowed for Windows filenames.
	subtitle = subtitle.replaceAll( "[\\s" + Pattern.quote( "\\/:*?\"<>|" ) + "]", "" );

	LoggerContext context = (LoggerContext)LogManager.getContext();
	Configuration config = context.getConfiguration();

	PatternLayout layout = PatternLayout.createLayout(
		"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%throwable%n",
		null, null, null, Charset.defaultCharset(), false, false, null, null
	);

	FileAppender appender = FileAppender.createAppender(
		"logs/log-" + subtitle + ".txt", "false", "false", "LogFile-" + subtitle, "true", "true", "true",
		"8192", layout, null, "false", "", config
	);

	org.apache.logging.log4j.core.Logger rootLogger = (org.apache.logging.log4j.core.Logger)LogManager.getRootLogger();
	rootLogger.addAppender( appender );
	appender.start();
}
 
开发者ID:kartoFlane,项目名称:hiervis,代码行数:27,代码来源:HierarchyVisualizer.java


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