本文整理汇总了Java中org.apache.logging.log4j.core.config.ConfigurationSource类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationSource类的具体用法?Java ConfigurationSource怎么用?Java ConfigurationSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationSource类属于org.apache.logging.log4j.core.config包,在下文中一共展示了ConfigurationSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLog4j
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
private static void initLog4j() {
String log4jConfigFolderPath = System.getProperty("motu-config-dir");
if (log4jConfigFolderPath != null && log4jConfigFolderPath.length() > 0) {
if (!log4jConfigFolderPath.endsWith("/")) {
log4jConfigFolderPath += "/";
}
} else {
System.err.println("Error while initializing log4j. Property is not set motu-config-dir or has a bad value");
}
// Do not use system property to avoid conflicts with other tomcat webapps
// System.setProperty("log4j.configurationFile", log4jConfigFolderPath + "log4j.xml");
try {
ConfigurationSource source = new ConfigurationSource(new FileInputStream(log4jConfigFolderPath + "log4j.xml"));
Configurator.initialize(null, source);
} catch (IOException e) {
System.err.println("Error while initializing log4j from file: " + log4jConfigFolderPath + "log4j.xml");
e.printStackTrace();
}
}
示例2: setUp
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的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());
}
示例3: StandaloneLoggerConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的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);
}
示例4: loadConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
protected void loadConfiguration(String location, LogFile logFile) {
Assert.notNull(location, "Location must not be null");
if (logFile != null) {
logFile.applyToSystemProperties();
}
try {
LoggerContext ctx = getLoggerContext();
URL url = ResourceUtils.getURL(location);
ConfigurationSource source = getConfigurationSource(url);
ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
}
catch (Exception ex) {
throw new IllegalStateException(
"Could not initialize Log4J2 logging from " + location, ex);
}
}
示例5: EmbeddedConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
/**
* Ctor. The configuration is built using instance of
* {@link Spec}:
*
* <ul>
* <li>The name is set to {@link Spec#getName()}.
* <li>Appenders from the parent object are cleared.
* <li>{@link Appender}s are created
* {@link #buildAppenders(Spec)}.
* <li>{@link LoggerConfig}s are created using
* {@link #buildLoggerConfigs(Spec)}.
* <li>Every {@link LoggerConfig} is configured with its
* {@link Appender} using
* {@link #configureLoggerAppenders(Spec, Map, Map)}.
* <li>Root loggers are configured.
* </ul>
*
* @param spec
*/
EmbeddedConfiguration(Spec spec) {
super(ConfigurationSource.NULL_SOURCE);
setName(spec.getName());
// Clean up first
getAppenders().clear();
getRootLogger().getAppenders().clear();
// Build Appenders
final Map<String, Appender> appenders = buildAppenders(spec);
final Map<String, SyslogAppender> syslogAppenders = buildSyslogAppenders(spec);
// Build Logger Configs
final Map<String, LoggerConfig> loggers = buildLoggerConfigs(spec);
// Configure loggers with appenders
configureLoggerAppenders(spec, appenders, loggers);
// Configure root logger appenders
configureRootLogger(spec, appenders, syslogAppenders);
}
示例6: CustomConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的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);
}
示例7: setConfigText
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
@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);
}
}
示例8: reconfigure
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
@Override
public Configuration reconfigure() {
LOGGER.debug("Reconfiguring composite configuration");
final List<AbstractConfiguration> configs = new ArrayList<>();
final ConfigurationFactory factory = ConfigurationFactory.getInstance();
for (final AbstractConfiguration config : configurations) {
final ConfigurationSource source = config.getConfigurationSource();
final URI sourceURI = source.getURI();
Configuration currentConfig = config;
if (sourceURI == null) {
LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored",
config.getName());
} else {
currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
if (currentConfig == null) {
LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
}
}
configs.add((AbstractConfiguration) currentConfig);
}
return new CompositeConfiguration(configs);
}
示例9: getContext
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
/**
* Loads the LoggerContext using the ContextSelector.
* @param fqcn The fully qualified class name of the caller.
* @param loader The ClassLoader to use or null.
* @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext.
* @param currentContext If true returns the current Context, if false returns the Context appropriate
* for the caller if a more appropriate Context can be determined.
* @param source The configuration source.
* @return The LoggerContext.
*/
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
final boolean currentContext, final ConfigurationSource source) {
final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext, null);
if (externalContext != null && ctx.getExternalContext() == null) {
ctx.setExternalContext(externalContext);
}
if (ctx.getState() == LifeCycle.State.INITIALIZED) {
if (source != null) {
ContextAnchor.THREAD_CONTEXT.set(ctx);
final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, source);
LOGGER.debug("Starting LoggerContext[name={}] from configuration {}", ctx.getName(), source);
ctx.start(config);
ContextAnchor.THREAD_CONTEXT.remove();
} else {
ctx.start();
}
}
return ctx;
}
示例10: testLoggerReconfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
@Test
public void testLoggerReconfiguration() throws Exception {
setLogLevel(logger, Level.ERROR);
Map<String, Long> expectedCounts = getCurrentCounts();
expectedCounts.compute("total", (s, aLong) -> aLong + 1);
expectedCounts.compute("error", (s, aLong) -> aLong + 1);
Properties properties = new Properties();
properties.setProperty("name", "PropertiesConfig");
properties.setProperty("appenders", "console");
properties.setProperty("appender.console.type", "Console");
properties.setProperty("appender.console.name", "STDOUT");
properties.setProperty("rootLogger.level", "debug");
properties.setProperty("rootLogger.appenderRefs", "stdout");
properties.setProperty("rootLogger.appenderRefs", "stdout");
properties.setProperty("rootLogger.appenderRef.stdout.ref", "STDOUT");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
properties.store(baos, null);
ConfigurationSource source = new ConfigurationSource(
new ByteArrayInputStream(baos.toByteArray()));
PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
LoggerContext context = (LoggerContext) LogManager.getContext(false);
PropertiesConfiguration configuration = factory.getConfiguration(context, source);
configuration.start();
context.updateLoggers(configuration);
logger.error("error!");
assertEquals(expectedCounts, getCurrentCounts());
}
示例11: BasicConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
public BasicConfiguration() {
super(null, ConfigurationSource.NULL_SOURCE);
final LoggerConfig root = getRootLogger();
final String name = System.getProperty(DEFAULT_LEVEL);
final Level level = (name != null && Level.getLevel(name) != null) ? Level.getLevel(name) : Level.ERROR;
root.setLevel(level);
}
示例12: getConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
if (source != null && source != ConfigurationSource.NULL_SOURCE) {
if (LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) {
return new DefaultConfiguration();
}
}
return null;
}
示例13: loadConfiguration
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
protected void loadConfiguration(String location, LogFile logFile) {
Assert.notNull(location, "Location must not be null");
try {
LoggerContext ctx = getLoggerContext();
URL url = ResourceUtils.getURL(location);
ConfigurationSource source = getConfigurationSource(url);
ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
}
catch (Exception ex) {
throw new IllegalStateException(
"Could not initialize Log4J2 logging from " + location, ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:Log4J2LoggingSystem.java
示例14: getConfigurationSource
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
private ConfigurationSource getConfigurationSource(URL url) throws IOException {
InputStream stream = url.openStream();
if (FILE_PROTOCOL.equals(url.getProtocol())) {
return new ConfigurationSource(stream, ResourceUtils.getFile(url));
}
return new ConfigurationSource(stream, url);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:Log4J2LoggingSystem.java
示例15: getConfigurationSource
import org.apache.logging.log4j.core.config.ConfigurationSource; //导入依赖的package包/类
private ConfigurationSource getConfigurationSource(URL url) throws IOException {
InputStream stream = url.openStream();
if (ResourceUtils.isFileURL(url)) {
return new ConfigurationSource(stream, ResourceUtils.getFile(url));
}
return new ConfigurationSource(stream, url);
}