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


Java LoggerConfig.setLevel方法代码示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: setLogLevel

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Override
public void setLogLevel(String category, String level) {
  LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  LoggerConfig loggerConfig = getLoggerConfig(ctx, category);
  if (loggerConfig != null) {
    boolean madeChanges = false;
    if (level == null || "unset".equals(level) || "null".equals(level)) {
      level = Level.OFF.toString();
      loggerConfig.setLevel(Level.OFF);
      madeChanges = true;
    } else {
      try {
        loggerConfig.setLevel(Level.valueOf(level));
        madeChanges = true;
      } catch (IllegalArgumentException iae) {
        watcherLog.error(level+" is not a valid log level! Valid values are: "+getAllLevels());
      }
    }
    if (madeChanges) {
      ctx.updateLoggers();
      watcherLog.info("Set log level to '" + level + "' for category: " + category);
    }
  } else {
    watcherLog.warn("Cannot set level to '" + level + "' for category: " + category + "; no LoggerConfig found!");
  }
}
 
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:27,代码来源:Log4j2Watcher.java

示例7: setupLogging

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

示例8: setLevel

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

示例9: addFileAppender

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

示例10: addServerAppender

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

示例11: main

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

示例12: resetLevel

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

示例13: CustomConfiguration

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
 * Constructor to create the default configuration.
 */
public CustomConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
    super(loggerContext, source);

    setName(CONFIG_NAME);
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder()
            .withPattern(DEFAULT_PATTERN)
            .withConfiguration(this)
            .build();
    final Appender appender = ConsoleAppender.createDefaultAppenderForLayout(layout);
    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.ERROR;
    root.setLevel(level);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:CustomConfiguration.java

示例14: resetLevel

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

示例15: initLogging

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


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