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


Java Configuration.getLoggerConfig方法代码示例

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


在下文中一共展示了Configuration.getLoggerConfig方法的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: 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

示例3: applyDelegate

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

示例4: addFileAppender

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

示例5: testReadException

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

示例6: setupLogging

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void setupLogging() {
    Level level = Level.getLevel(logLevel.name());
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    // Setup the root logger to the requested log level
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(level);
    // Dump the requests/responses when requested
    if (logRequests) {
        loggerConfig = config.getLoggerConfig("org.apache.cxf.services");
        if (level.isLessSpecificThan(Level.INFO)) {
            loggerConfig.setLevel(level);
        } else {
            loggerConfig.setLevel(Level.INFO);
        }
    }
    ctx.updateLoggers();
}
 
开发者ID:OpenNMS,项目名称:wsman,代码行数:19,代码来源:WSManCli.java

示例7: setLevel

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void setLevel(Level level) {
	LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	Configuration config = ctx.getConfiguration();
	LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); 
	loggerConfig.setLevel(level);
	ctx.updateLoggers();
		if (level == Level.ERROR) {
			logger.error("<- This level is successfully initialized");
		}
		if (level == Level.WARN) {
			logger.warn("<- This level is successfully initialized");
		}
		if (level == Level.DEBUG) {
			logger.debug("<- This level is successfully initialized");
		}
		if (level == Level.INFO) {
			logger.info("<- This level is successfully initialized");
		}
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:20,代码来源:MyLogger.java

示例8: addFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void addFileAppender(final String loggerPath, final File logFile, final AppConfig appConfig)
	throws IOException
{
	// retrieve the logger context
	LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	Configuration configuration = loggerContext.getConfiguration();
	
	// retrieve the root logger config
	LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
	loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
	
	// Define log pattern layout
	PatternLayout layout = PatternLayout.createLayout(DEFAULT_LOGGER_PATTERN, null, null, null,
		Charset.defaultCharset(), false, false, null, null);
	
	// create the appenders
	FileAppender fileAppender =
		FileAppender.createAppender(logFile.getAbsolutePath(), "true", "false", "fileAppender",
			"true", "true", "true", "8192", layout, null, "false", null, null);
	fileAppender.start();
	
	// add the appenders
	loggerConfig.addAppender(fileAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
	loggerContext.updateLoggers();
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:26,代码来源:LoggerUtil.java

示例9: addServerAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void addServerAppender(final String loggerPath, final AppConfig appConfig)
	throws IOException
{
	// retrieve the logger context
	LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	Configuration configuration = loggerContext.getConfiguration();
	
	// retrieve the root logger config
	LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
	loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
	
	// create the appenders
	ServerLoggerAppender serverLoggerAppender = ServerLoggerAppender.createAppender("serverLoggerAppender");
	serverLoggerAppender.start();
	
	// add the appenders
	loggerConfig.addAppender(serverLoggerAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
	loggerContext.updateLoggers();
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:20,代码来源:LoggerUtil.java

示例10: main

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{

        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
        loggerConfig.setLevel(Level.DEBUG);
        ctx.updateLoggers();

        MultiLabelClfDataSet dataSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "scene/train"),
                DataSetType.ML_CLF_DENSE, true);
        MultiLabelClfDataSet testSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "scene/test"),
                DataSetType.ML_CLF_DENSE, true);
        AugmentedLR augmentedLR = new AugmentedLR(dataSet.getNumFeatures(), 1);
        double[][] gammas = new double[dataSet.getNumDataPoints()][1];
        for (int i=0;i<dataSet.getNumDataPoints();i++){
            gammas[i][0]=1;
        }
        AugmentedLRLoss loss = new AugmentedLRLoss(dataSet, 0, gammas, augmentedLR, 1, 1);
        LBFGS lbfgs = new LBFGS(loss);

        for (int i=0;i<100;i++){
            lbfgs.iterate();
            System.out.println(loss.getValue());
        }

    }
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:27,代码来源:AugmentedLRLossTest.java

示例11: resetLevel

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void resetLevel() {
    logger.entry();
    List<LogEvent> events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
    app.clear();
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    /* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
       LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
    */
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();  // This causes all Loggers to refetch information from their LoggerConfig.
    logger.entry();
    events = app.getEvents();
    assertTrue("Incorrect number of events. Expected 0, actual " + events.size(), events.size() == 0);
    app.clear();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:20,代码来源:LoggerUpdateTest.java

示例12: resetLevel

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Test
public void resetLevel() {
    final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
    logger.traceEntry();
    List<LogEvent> events = app.getEvents();
    assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
    app.clear();
    final LoggerContext ctx = LoggerContext.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    /* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
       LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
    */
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();  // This causes all Loggers to refetch information from their LoggerConfig.
    logger.traceEntry();
    events = app.getEvents();
    assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:LoggerUpdateTest.java

示例13: initLogging

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void initLogging(final Level level) {
	loglevel = level;
	final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	final Configuration config = ctx.getConfiguration();
	final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
	loggerConfig.setLevel(level);
	ctx.updateLoggers();
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:9,代码来源:LogFacade.java

示例14: findAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static Appender findAppender(final Logger logger, final Class<? extends Appender> clazz) {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
    for (final Map.Entry<String, Appender> entry : loggerConfig.getAppenders().entrySet()) {
        if (entry.getValue().getClass().equals(clazz)) {
            return entry.getValue();
        }
    }
    return null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:Loggers.java

示例15: setLevel

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public void setLevel(Level level) {
	LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
	Configuration config = ctx.getConfiguration();
	LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
	loggerConfig.setLevel(toLog4jLevel(level));
	ctx.updateLoggers();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:8,代码来源:Log4j2LoggerAdapter.java


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