當前位置: 首頁>>代碼示例>>Java>>正文


Java LoggerContext.setConfigLocation方法代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.LoggerContext.setConfigLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java LoggerContext.setConfigLocation方法的具體用法?Java LoggerContext.setConfigLocation怎麽用?Java LoggerContext.setConfigLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.logging.log4j.core.LoggerContext的用法示例。


在下文中一共展示了LoggerContext.setConfigLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: LindenServer

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public LindenServer(String conf) throws Exception {
  File lindenProperties = new File(FilenameUtils.concat(conf, LINDEN_PROPERTIES));
  File schemaXml = new File(FilenameUtils.concat(conf, SCHEMA_XML));
  Preconditions.checkArgument(lindenProperties.exists(), "can not find linden.properties.");

  lindenConf = LindenConfigBuilder.build(lindenProperties);
  if (schemaXml.exists()) {
    LindenSchema schema = LindenSchemaBuilder.build(schemaXml);
    lindenConf.setSchema(schema);
  } else {
    throw new Exception("schema.xml not found.");
  }
  port = lindenConf.getPort();
  Preconditions.checkNotNull(lindenConf.getLogPath(), "log path can not be null.");
  System.setProperty(LOG_PATH, lindenConf.getLogPath());
  System.setProperty(LOG4J_SHUTDOWN_HOOK_ENABLED, "false");
  System.setProperty(LOG4J_CONTEXT_SELECTOR, "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
  LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  ctx.setConfigLocation(new File(FilenameUtils.concat(conf, LOG4j2_XML)).toURI());
  ctx.reconfigure();
  LOGGER = LoggerFactory.getLogger(LindenServer.class);
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:23,代碼來源:LindenServer.java

示例2: setUp

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
	super.setUp();

	initLogFormatter();
	System.getProperties().setProperty(Logging.LOG_CLASS_NAME, "com.devexperts.logging.Log4j2Logging");

	// Create log file in folder that will be eventually cleared - "deleteOnExit" does not work for log files.
	BUILD_TEST_DIR.mkdirs();
	logFile = File.createTempFile("test.", ".log", BUILD_TEST_DIR);
	final Properties props = new Properties();
	props.load(Log4jCompatibilityTest.class.getResourceAsStream("/test.log4j2.properties"));
	props.setProperty("appender.file.fileName", logFile.getPath());
	LoggerContext context = (LoggerContext)LogManager.getContext(false);
	ConfigurationFactory.setConfigurationFactory(new PropertiesConfigurationFactory() {
		@Override
		public PropertiesConfiguration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
			return new PropertiesConfigurationBuilder()
				.setConfigurationSource(source)
				.setRootProperties(props)
				.setLoggerContext(loggerContext)
				.build();
		}
	});
	context.setConfigLocation(Log4jCompatibilityTest.class.getResource("/test.log4j2.properties").toURI());
}
 
開發者ID:Devexperts,項目名稱:QD,代碼行數:27,代碼來源:Log4j2CompatibilityTest.java

示例3: setLog4jConfigFile

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public static void setLog4jConfigFile(String log4jConfigFile) {
	ConfigHelper.log4jConfigFile = log4jConfigFile;
	ConfigHelper.log4jConfigUrl = null;
	//
	int pos = log4jConfigFile.indexOf("log4j2");
	// log4j
	if (pos < 0) {
		PropertyConfigurator.configure(log4jConfigFile);
		LOGGER.info("Using Log4j");

	} else {
		// log4j2
		LoggerContext context = (LoggerContext) LogManager.getContext(false);
		context.setConfigLocation(new File(log4jConfigFile).toURI());
		LOGGER.info("Using Log4j2");
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:18,代碼來源:ConfigHelper.java

示例4: setLog4jConfigUrl

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public static void setLog4jConfigUrl(URL log4jConfigUrl) throws Exception {
	ConfigHelper.log4jConfigUrl = log4jConfigUrl;
	ConfigHelper.log4jConfigFile = log4jConfigUrl.getFile();
	//
	int pos = log4jConfigFile.indexOf("log4j2");
	// log4j
	if (pos < 0) {
		PropertyConfigurator.configure(log4jConfigFile);
		LOGGER.info("Using Log4j");
	} else {
		// log4j2
		LoggerContext context = (LoggerContext) LogManager.getContext(false);
		context.setConfigLocation(log4jConfigUrl.toURI());
		LOGGER.info("Using Log4j2");
	}
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:17,代碼來源:ConfigHelper.java

示例5: setExternalLoggerConfig

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
private boolean setExternalLoggerConfig() {
    log.info("External log configuration: " + appConfiguration.getExternalLoggerConfiguration());
    if (StringUtils.isEmpty(appConfiguration.getExternalLoggerConfiguration())) {
        return false;
    }
    File log4jFile = new File(appConfiguration.getExternalLoggerConfiguration());
    if (!log4jFile.exists()) {
        log.info("External log configuration does not exist.");
        return false;
    }
    LoggerContext loggerContext = LoggerContext.getContext(false);
    loggerContext.setConfigLocation(log4jFile.toURI());
    loggerContext.reconfigure();

    configurationUpdateEvent.select(ConfigurationUpdate.Literal.INSTANCE).fire(this.appConfiguration);
    return true;
}
 
開發者ID:GluuFederation,項目名稱:oxAuth,代碼行數:18,代碼來源:LoggerService.java

示例6: testRollingFileAppenderWithReconfigure

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@Test
public void testRollingFileAppenderWithReconfigure() throws Exception {
    logger.debug("Before reconfigure");

    @SuppressWarnings("resource") // managed by the rule.
    final LoggerContext context = loggerContextRule.getLoggerContext();
    Configuration config = context.getConfiguration();
    context.setConfigLocation(new URI(CONFIG));
    context.reconfigure();
    logger.debug("Force a rollover");
    final File dir = new File(DIR);
    for (int i = 0; i < MAX_TRIES; ++i) {
        Thread.sleep(200);
        if (config != context.getConfiguration()) {
            break;
        }
    }

    assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0);
    final File[] files = dir.listFiles();
    assertNotNull(files);
    assertThat(dir.listFiles().length, is(equalTo(2)));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:24,代碼來源:RollingAppenderDirectWriteWithReconfigureTest.java

示例7: reInitLogConfig

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
/**
 * 根據配置文件路徑初始化日誌配置
 * @param logConfigpath
 */
public static void reInitLogConfig(String logConfigpath)
{
	try {
		 LoggerContext context =(LoggerContext)LogManager.getContext(false);
	     context.setConfigLocation(new File(logConfigpath).toURI());
	     context.reconfigure(); //重新初始化Log4j2的配置上下文
	     Logger log=LoggerFactory.getLogger(Log4jUtil.class);
		 log.info("日誌配置重新初始化完成:"+logConfigpath);
	} catch (Exception e) {
		e.printStackTrace();
	}  
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:17,代碼來源:Log4jUtil.java

示例8: initLog4j

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public static void initLog4j(String configFile)
{
  configFile = "log4j2-server.xml";
  if (getProperty(ITEMS.NODE_TYPE.name()) == null)
    setProperty("NODE_TYPE", "");
  if (getProperty(ITEMS.NODE_NAME.name()) == null)
    setProperty("NODE_NAME", "");
  String resolvedLocation = SystemPropertyUtils.resolvePlaceholders("log4j2-server.xml");
  
  URL url;
  try
  {
    url = ServerConfigHelper.class.getClassLoader().getResource(configFile);
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    context.setConfigLocation(url.toURI());
    LogUtil.init();
  }
  catch (URISyntaxException e)
  {
    e.printStackTrace();
  }
  
  // System.setProperty("log4j.configurationFile", configFile);
  
  // try
  // {
  // if (!configFile.startsWith("classpath"))
  // configFile = "classpath:" + configFile;
  // Log4jConfigurer.initLogging(configFile);
  // }
  // catch (FileNotFoundException e)
  // {
  // System.err.println("File " + configFile + " not exists!");
  // }
}
 
開發者ID:iisi-nj,項目名稱:GemFireLite,代碼行數:36,代碼來源:ServerConfigHelper.java

示例9: main

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public static void main(String[] args) throws URISyntaxException
{
  File f = new File("d:/tmp/x/log4j2_jnj.xml");
  LoggerContext context = (LoggerContext) LogManager.getContext(false);
  context.setConfigLocation(f.toURI());
  
  Logger log = LogManager.getLogger("com.gemstone.xx");
  log.info("inof");
  log.debug("inof");
  log.info("inof");
  
}
 
開發者ID:iisi-nj,項目名稱:GemFireLite,代碼行數:13,代碼來源:Testlog.java

示例10: configure

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
/**
 * Configures Logging in case it has not been configured via this method
 * before.
 */
public static void configure() {
    if (ALREADY_CONFIGURED.compareAndSet(false, true)) {
        final File log4jFile = new File("log4j2.xml");

        if (log4jFile.isFile()) {
            LoggerContext context = (LoggerContext) LogManager.getContext(false);
            context.setConfigLocation(log4jFile.toURI());
        } else {
            final Logger logger = LogManager.getLogger(LoggingConfigurator.class);
            logger.info("log4j configuration file ('" + log4jFile.getAbsolutePath() + "') not found.");
        }
    }
}
 
開發者ID:TweetWallFX,項目名稱:TweetwallFX,代碼行數:18,代碼來源:LoggingConfigurator.java

示例11: init

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
private void init() {
	final String loggingFile = ConfigurationService.getConfigurationProperty("logging", "log4j");

	final LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
	final File file = new File(loggingFile);

	// this will force a reconfiguration
	context.setConfigLocation(file.toURI());
}
 
開發者ID:comdata,項目名稱:HomeAutomation,代碼行數:10,代碼來源:LogConfigurator.java

示例12: updateLoggerConfigLocation

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
/**
 * First trying to set external logger config from GluuAppliance.
 * If there is no valid external path to log4j2.xml location then set default configuration.
 */
public void updateLoggerConfigLocation() {
    if (setExternalLoggerConfig())
        return;
    LoggerContext loggerContext = LoggerContext.getContext(false);
    loggerContext.setConfigLocation(null);
    loggerContext.reconfigure();
}
 
開發者ID:GluuFederation,項目名稱:oxTrust,代碼行數:12,代碼來源:LoggerService.java

示例13: setExternalLoggerConfig

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
private boolean setExternalLoggerConfig() {
    GluuAppliance updateAppliance = applianceService.getAppliance();
    if (StringUtils.isEmpty(updateAppliance.getOxLogConfigLocation())) {
        return false;
    }
    File log4jFile = new File(updateAppliance.getOxLogConfigLocation());
    if (!log4jFile.exists())
        return false;
    LoggerContext loggerContext = LoggerContext.getContext(false);
    loggerContext.setConfigLocation(log4jFile.toURI());
    loggerContext.reconfigure();

    configurationUpdateEvent.select(ConfigurationUpdate.Literal.INSTANCE).fire(this.appConfiguration);
    return true;
}
 
開發者ID:GluuFederation,項目名稱:oxTrust,代碼行數:16,代碼來源:LoggerService.java

示例14: printTestHeader

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public static void printTestHeader ( String description ) {

		if ( !isJvmInfoPrinted ) {
			isJvmInfoPrinted = true;
			System.out.println( "Working Directory = " +
					System.getProperty( "user.dir" ) );
			StringBuffer sbuf = new StringBuffer();
			// Dump log4j first - if it does not work, nothing will
			String resource = "log4j2-junit.yml";
			URL configFile = InitializeLogging.class.getResource( resource );

			if ( configFile == null ) {
				System.out.println( "ERROR: Failed to find log configuration file in classpath: " + resource );

				System.exit( 99 );
			}
			try {
				sbuf.append( "\n\n ** " + resource + " found in: " + configFile.toURI().getPath() );
				
				LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
				// this will force a reconfiguration
				context.setConfigLocation(configFile.toURI());
			} catch (Exception e) {
				
				System.out.println( "ERROR: Failed to resolve path: " + resource );
				System.exit( 99 );
			}

			// Now dump nicely formatted classpath.
			sbuf.append( "\n\n ====== JVM Classpath is: \n"
					+ WordUtils.wrap( System.getProperty( "java.class.path" ).replaceAll( ";", " " ), 140 ) );
			System.out.println( sbuf );
			
			String testDir = System.getProperty( "csapTest" ) ;
			if ( testDir == null) {
				testDir = System.getProperty( "user.home" ) + "/csap" ;
			}
			logger.info( "External configuration: " + testDir );
			File externalConfiguration = new File(testDir) ;
				
			logger.info( "Adding System property: spring.config.location, {}" ,  externalConfiguration.toPath().toUri()  );
			System.setProperty( "spring.config.location", externalConfiguration.toPath().toUri().toString() ) ;
			
			File testFolder = new File( "target/junit" );
			logger.info( "Deleting: {}", testFolder.getAbsolutePath() );
			FileUtils.deleteQuietly( testFolder );

		}

		// https://logging.apache.org/log4j/2.0/faq.html
		logger.info( "\n\n *********************  {}  ***********************\n\n", description );
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:53,代碼來源:InitializeLogging.java

示例15: initializeLogging

import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
/**
 * Auxiliary method to (re)initialize the logging. This method is typically called from
 * the PropertiesManager when a external log4j2 configuration is provided, while at the
 * same time no CLI parameter was given.
 *
 * Setting the new config location is enough, as it will trigger a reconfigure
 * automatically.
 *
 * @param pathToLogConfiguration
 *  A path to the external log configuration file.
 */
public static void initializeLogging(String pathToLogConfiguration) {
    Path path = FileSystems.getDefault().getPath(pathToLogConfiguration);
    LOGGER.trace("Path to log configuration: {} -> file exists: {}", pathToLogConfiguration, Files.exists(path));
    LoggerContext loggerContext = LoggerContext.getContext(false);
    loggerContext.setConfigLocation(path.toUri());
}
 
開發者ID:Technolords,項目名稱:microservice-mock,代碼行數:18,代碼來源:LogManager.java


注:本文中的org.apache.logging.log4j.core.LoggerContext.setConfigLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。