當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。