当前位置: 首页>>代码示例>>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;未经允许,请勿转载。