use of org.apache.logging.log4j.core.config.ConfigurationSource in project metrics by dropwizard.
the class InstrumentedAppenderConfigTest method setUp.
@Before
public void setUp() throws Exception {
source = new ConfigurationSource(this.getClass().getClassLoader().getResourceAsStream("log4j2-testconfig.xml"));
context = Configurator.initialize(null, source);
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class BuiltConfiguration method setMonitorInterval.
public void setMonitorInterval(final int intervalSeconds) {
if (this instanceof Reconfigurable && intervalSeconds > 0) {
final ConfigurationSource configSource = getConfigurationSource();
if (configSource != null) {
final File configFile = configSource.getFile();
if (intervalSeconds > 0) {
getWatchManager().setIntervalSeconds(intervalSeconds);
if (configFile != null) {
final FileWatcher watcher = new ConfiguratonFileWatcher((Reconfigurable) this, listeners);
getWatchManager().watchFile(configFile, watcher);
}
}
}
}
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class LoggerContextAdmin method getConfigText.
@Override
public String getConfigText(final String charsetName) throws IOException {
try {
final ConfigurationSource source = loggerContext.getConfiguration().getConfigurationSource();
final ConfigurationSource copy = source.resetInputStream();
final Charset charset = Charset.forName(charsetName);
return readContents(copy.getInputStream(), charset);
} catch (final Exception ex) {
final StringWriter sw = new StringWriter(BUFFER_SIZE);
ex.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class LoggerContextAdmin method setConfigText.
@Override
public void setConfigText(final String configText, final String charsetName) {
LOGGER.debug("---------");
LOGGER.debug("Remote request to reconfigure from config text.");
try {
final InputStream in = new ByteArrayInputStream(configText.getBytes(charsetName));
final ConfigurationSource source = new ConfigurationSource(in);
final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(loggerContext, source);
loggerContext.start(updated);
LOGGER.debug("Completed remote request to reconfigure from config text.");
} catch (final Exception ex) {
final String msg = "Could not reconfigure from config text";
LOGGER.error(msg, ex);
throw new IllegalArgumentException(msg, ex);
}
}
use of org.apache.logging.log4j.core.config.ConfigurationSource in project logging-log4j2 by apache.
the class LoggerContextAdmin method setConfigLocationUri.
@Override
public void setConfigLocationUri(final String configLocation) throws URISyntaxException, IOException {
if (configLocation == null || configLocation.isEmpty()) {
throw new IllegalArgumentException("Missing configuration location");
}
LOGGER.debug("---------");
LOGGER.debug("Remote request to reconfigure using location " + configLocation);
final File configFile = new File(configLocation);
ConfigurationSource configSource = null;
if (configFile.exists()) {
LOGGER.debug("Opening config file {}", configFile.getAbsolutePath());
configSource = new ConfigurationSource(new FileInputStream(configFile), configFile);
} else {
final URL configURL = new URL(configLocation);
LOGGER.debug("Opening config URL {}", configURL);
configSource = new ConfigurationSource(configURL.openStream(), configURL);
}
final Configuration config = ConfigurationFactory.getInstance().getConfiguration(loggerContext, configSource);
loggerContext.start(config);
LOGGER.debug("Completed remote request to reconfigure.");
}
Aggregations