本文整理匯總了Java中org.apache.logging.log4j.core.LoggerContext.reconfigure方法的典型用法代碼示例。如果您正苦於以下問題:Java LoggerContext.reconfigure方法的具體用法?Java LoggerContext.reconfigure怎麽用?Java LoggerContext.reconfigure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.reconfigure方法的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);
}
示例2: loadLogger
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
/**
* <p>
* This method loads the required properties into log4j for the logger
* </p>
*
* @param logFileDir
* Log file directory
* @param taskAttemptID
* The task attempt id
*
* @throws IOException
* If any error occurs
* @throws URISyntaxException
* @throws SAXException
* @throws ParserConfigurationException
* @throws TransformerException
*/
public static void loadLogger(String logFileDir, String taskAttemptID) throws IOException, URISyntaxException, ParserConfigurationException,
SAXException, TransformerException {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.reconfigure();
Configuration config = ctx.getConfiguration();
MemoryMappedFileAppender memoryMappedfileAppender = createMemoryMappedFileAppender(config, LOG_APPENDER_NAME + taskAttemptID, logFileDir, taskAttemptID, 0);
memoryMappedfileAppender.start();
AppenderRef[] ar = new AppenderRef [1];
ar[0] = AppenderRef.createAppenderRef(LOG_APPENDER_NAME + taskAttemptID , Level.INFO, null);
LoggerConfig lgf = LoggerConfig.createLogger("false",Level.INFO , LOG_CATEGORY + taskAttemptID , null, ar, null, config, null);
config.addLogger(LOG_CATEGORY + taskAttemptID, lgf);
ctx.getLogger(LOG_CATEGORY + taskAttemptID).addAppender(memoryMappedfileAppender);
ctx.updateLoggers();
ctx.start();
mapReduceLoggers = new ArrayList<Logger>(1);
mapReduceLoggers.add(LogManager.getLogger(LOG_CATEGORY + taskAttemptID));
LOG.debug("Finished loading logger");
}
示例3: updateLoggingSeverity
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
String loggingLevel = appConfiguration.getLoggingLevel();
if (StringHelper.isEmpty(loggingLevel)) {
return;
}
log.info("Setting loggers level to: '{}'", loggingLevel);
LoggerContext loggerContext = LoggerContext.getContext(false);
if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
log.info("Reloadming log4j configuration");
loggerContext.reconfigure();
return;
}
Level level = Level.toLevel(loggingLevel, Level.INFO);
for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
String loggerName = logger.getName();
if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu")) {
logger.setLevel(level);
}
}
}
示例4: 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;
}
示例5: updateLoggingSeverity
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
String loggingLevel = appConfiguration.getLoggingLevel();
if (StringHelper.isEmpty(loggingLevel)) {
return;
}
log.info("Setting loggers level to: '{}'", loggingLevel);
LoggerContext loggerContext = LoggerContext.getContext(false);
if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
log.info("Reloading log4j configuration");
loggerContext.reconfigure();
return;
}
Level level = Level.toLevel(loggingLevel, Level.INFO);
for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
String loggerName = logger.getName();
if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu") || level == Level.OFF) {
logger.setLevel(level);
}
}
}
示例6: tearDown
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
public void tearDown() throws SQLException {
final LoggerContext context = LoggerContext.getContext(false);
try {
String appenderName = "databaseAppender";
final Appender appender = context.getConfiguration().getAppender(appenderName);
assertNotNull("The appender '" + appenderName + "' should not be null.", appender);
assertTrue("The appender should be a JpaAppender.", appender instanceof JpaAppender);
((JpaAppender) appender).getManager().close();
} finally {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
PropertiesUtil.getProperties().reload();
context.reconfigure();
StatusLogger.getLogger().reset();
try (Statement statement = this.connection.createStatement();) {
statement.execute("SHUTDOWN");
}
this.connection.close();
}
}
示例7: setUp
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
final File file = new File("target/file-channel");
final boolean result = deleteFiles(file);
/*
* Clear out all other appenders associated with this logger to ensure we're
* only hitting the Avro appender.
*/
final int[] ports = findFreePorts(2);
System.setProperty("primaryPort", Integer.toString(ports[0]));
System.setProperty("alternatePort", Integer.toString(ports[1]));
primary = new EventCollector(ports[0]);
alternate = new EventCollector(ports[1]);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
ctx = (LoggerContext) LogManager.getContext(false);
ctx.reconfigure();
}
示例8: setUp
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
final File file = new File("target/persistent");
final boolean result = deleteFiles(file);
/*
* Clear out all other appenders associated with this logger to ensure we're
* only hitting the Avro appender.
*/
final int[] ports = findFreePorts(2);
System.setProperty("primaryPort", Integer.toString(ports[0]));
System.setProperty("alternatePort", Integer.toString(ports[1]));
primary = new EventCollector(ports[0]);
alternate = new EventCollector(ports[1]);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
ctx = (LoggerContext) LogManager.getContext(false);
ctx.reconfigure();
}
示例9: setupClass
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@BeforeClass
public static void setupClass() {
final File file = new File(STATUS_LOG);
file.delete();
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
final LoggerContext ctx = (LoggerContext) LogManager.getContext();
final Configuration config = ctx.getConfiguration();
if (config instanceof XMLConfiguration) {
final String name = ((XMLConfiguration) config).getName();
if (name == null || !name.equals("XMLConfigTest")) {
ctx.reconfigure();
}
} else {
ctx.reconfigure();
}
}
示例10: 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();
}
}
示例11: setupClass
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@BeforeClass
public static void setupClass() {
ThreadContext.clearAll();
ConfigurationFactory.setConfigurationFactory(cf);
final LoggerContext ctx = LoggerContext.getContext();
ctx.reconfigure();
}
示例12: init
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
private static void init() {
LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager
.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext();
context.removePropertyChangeListener(propertyChangeListener);
context.addPropertyChangeListener(propertyChangeListener);
context.reconfigure(); // propertyChangeListener invokes configureFastLoggerDelegating
configureLoggers(false, false);
}
示例13: 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();
}
示例14: 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;
}
示例15: after
import org.apache.logging.log4j.core.LoggerContext; //導入方法依賴的package包/類
@After
public void after() throws Exception {
LoggerContext ctx = (LoggerContext) LogManager.getContext();
ctx.reconfigure();
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
}