本文整理汇总了Java中ch.qos.logback.core.util.Loader.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java Loader.getResource方法的具体用法?Java Loader.getResource怎么用?Java Loader.getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.util.Loader
的用法示例。
在下文中一共展示了Loader.getResource方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeLogsOnFileAndConsole
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private void writeLogsOnFileAndConsole() {
loggers.debug("****Configuring Logger****");
try {
if(Platform.isRunning()){
System.setProperty(HYDROGRAPH_INSTALLATION_LOCATION, Platform.getInstallLocation().getURL().getPath());
ClassLoader loader = new URLClassLoader(new URL[]
{new File(Platform.getInstallLocation().getURL().getPath() + LOG_DIR).toURI().toURL()});
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
URL url = Loader.getResource(CLASSIC_FILE, loader);
if (url != null) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(url);
lc.start();
}
loggers.debug("****Logger Configured Successfully****");
}
} catch(MalformedURLException|JoranException exception){
loggers.error("Failed to configure the logger {}", exception);
}
}
示例2: findConfigFileURLFromSystemProperties
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
String logbackConfigFile = OptionHelper.getSystemProperty("logback.configurationFile");
if (logbackConfigFile != null) {
URL result = null;
URL f;
try {
result = new URL(logbackConfigFile);
URL e = result;
return e;
} catch (MalformedURLException var13) {
result = Loader.getResource(logbackConfigFile, classLoader);
if (result == null) {
File f1 = new File(logbackConfigFile);
if (!f1.exists() || !f1.isFile()) {
return null;
}
try {
result = f1.toURI().toURL();
URL e1 = result;
return e1;
} catch (MalformedURLException var12) {
return null;
}
}
f = result;
} finally {
if (updateStatus) {
this.statusOnResourceSearch(logbackConfigFile, classLoader, result);
}
}
return f;
} else {
return null;
}
}
示例3: getResource
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
URL url = Loader.getResource(filename, myClassLoader);
if (updateStatus) {
this.statusOnResourceSearch(filename, myClassLoader, url);
}
return url;
}
示例4: urlByResourceName
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL urlByResourceName(StatusManager sm, String resourceName) {
sm.add(new InfoStatus("Searching for [" + resourceName + "]",
this));
URL url = Loader.getResource(resourceName, Loader.getTCL());
if (url != null) {
return url;
}
return Loader.getResourceBySelfClassLoader(resourceName);
}
示例5: findConfigFileURLFromSystemProperties
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY);
if (logbackConfigFile != null) {
URL result = null;
try {
result = new URL(logbackConfigFile);
return result;
} catch (MalformedURLException e) {
// so, resource is not a URL:
// attempt to get the resource from the class path
result = Loader.getResource(logbackConfigFile, classLoader);
if (result != null) {
return result;
}
File f = new File(logbackConfigFile);
if (f.exists() && f.isFile()) {
try {
result = f.toURI().toURL();
return result;
} catch (MalformedURLException e1) {
}
}
} finally {
if (updateStatus) {
statusOnResourceSearch(logbackConfigFile, classLoader, result);
}
}
}
return null;
}
示例6: getResource
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
URL url = Loader.getResource(filename, myClassLoader);
if (updateStatus) {
statusOnResourceSearch(filename, myClassLoader, url);
}
return url;
}
示例7: shouldConfigureFromXmlFile
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
@Test
public void shouldConfigureFromXmlFile() throws MalformedURLException, JoranException {
LoggerContext loggerContext = new LoggerContext();
ContextInitializer initializer = new ContextInitializer(loggerContext);
assertNull(loggerContext.getObject(CoreConstants.SAFE_JORAN_CONFIGURATION));
URL configurationFileUrl = Loader.getResource("BOO_logback-test.xml", Thread.currentThread().getContextClassLoader());
initializer.configureByResource(configurationFileUrl);
assertNotNull(loggerContext.getObject(CoreConstants.SAFE_JORAN_CONFIGURATION));
}
示例8: shouldConfigureFromGroovyScript
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
@Test
public void shouldConfigureFromGroovyScript() throws MalformedURLException, JoranException {
LoggerContext loggerContext = new LoggerContext();
ContextInitializer initializer = new ContextInitializer(loggerContext);
assertNull(loggerContext.getObject(CoreConstants.CONFIGURATION_WATCH_LIST));
URL configurationFileUrl = Loader.getResource("test.groovy", Thread.currentThread().getContextClassLoader());
initializer.configureByResource(configurationFileUrl);
assertNotNull(loggerContext.getObject(CoreConstants.CONFIGURATION_WATCH_LIST));
}
示例9: shouldThrowExceptionIfUnexpectedConfigurationFileExtension
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
@Test
public void shouldThrowExceptionIfUnexpectedConfigurationFileExtension() throws JoranException {
LoggerContext loggerContext = new LoggerContext();
ContextInitializer initializer = new ContextInitializer(loggerContext);
URL configurationFileUrl = Loader.getResource("README.txt", Thread.currentThread().getContextClassLoader());
try {
initializer.configureByResource(configurationFileUrl);
fail("Should throw LogbackException");
} catch (LogbackException expectedException) {
// pass
}
}
示例10: autoConfig
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
public static void autoConfig(Auditor auditor, ClassLoader classLoader)
throws AuditException {
String autoConfigFileByProperty = System
.getProperty(AUTOCONFIG_FILE_PROPERTY);
String pathPrefix = clientApplication.getName() + "/";
URL url = null;
InputStream inputStream = null;
if (StringUtils.hasText(host) && port > 0) {
final byte[] bytes = new StringBuilder()
.append("<auditor><appender name=\"server\" class=\"ch.qos.logback.audit.client.net.SocketAuditAppender\"><remoteHost>")
.append(host)
.append("</remoteHost><port>")
.append(port)
.append("</port></appender></auditor>")
.toString()
.getBytes(StandardCharsets.UTF_8);
inputStream = new ByteArrayInputStream(bytes);
} else if (autoConfigFileByProperty != null) {
url = Loader.getResource(pathPrefix + autoConfigFileByProperty,
classLoader);
} else {
url = Loader.getResource(pathPrefix + TEST_AUTOCONFIG_FILE, classLoader);
if (url == null) {
url = Loader.getResource(pathPrefix + AUTOCONFIG_FILE, classLoader);
}
}
if (inputStream != null) {
configureByInputStream(auditor, inputStream);
try {
inputStream.close();
} catch (IOException e) {
throw new AuditException("Failed loading configuration file from input stream: " + e.getMessage(), e);
}
} else if (url != null) {
configureByResource(auditor, url);
} else {
String errMsg;
if (autoConfigFileByProperty != null) {
errMsg = "Failed to find configuration file [" + pathPrefix
+ autoConfigFileByProperty + "].";
} else {
errMsg = "Failed to find logback-audit configuration files ["
+ pathPrefix + TEST_AUTOCONFIG_FILE + "] or [" + pathPrefix
+ AUTOCONFIG_FILE + "].";
}
throw new AuditException(errMsg);
}
}
示例11: getResource
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL getResource(String filename, ClassLoader myClassLoader) {
return Loader.getResource(filename, myClassLoader);
}
示例12: getLoggerContext
import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
public LoggerContext getLoggerContext() {
//System.out.println("getLoggerContext request");
// First check if ThreadLocal has been set already
LoggerContext lc = threadLocal.get();
if (lc != null) {
//System.out.printf("Thread local found: %s\n", lc.getName());
return lc;
}
if (contextName == null) {
//System.out.println("Context name was null, returning default");
// We return the default context
return defaultContext;
} else {
// Let's see if we already know such a context
LoggerContext loggerContext = contextMap.get(contextName);
//System.out.printf("Logger context for %s is %s\n", contextName, loggerContext);
if (loggerContext == null) {
// We have to create a new LoggerContext
loggerContext = new LoggerContext();
loggerContext.setName(contextName);
// allow override using logbacks system prop
String overrideProperty = System.getProperty("logback.configurationFile");
if (overrideProperty == null) {
contextConfigFile = String.format("logback-%s.xml", contextName);
} else {
contextConfigFile = String.format(overrideProperty, contextName);
}
System.out.printf("Context logger config file: %s\n", contextConfigFile);
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
//System.out.printf("Thread context cl: %s\n", classloader);
//ClassLoader classloader2 = Loader.class.getClassLoader();
//System.out.printf("Loader tcl: %s\n", classloader2);
//URL url = Loader.getResourceBySelfClassLoader(contextConfigFile);
URL url = Loader.getResource(contextConfigFile, classloader);
if (url != null) {
try {
JoranConfigurator configurator = new JoranConfigurator();
loggerContext.reset();
configurator.setContext(loggerContext);
configurator.doConfigure(url);
} catch (JoranException e) {
StatusPrinter.print(loggerContext);
}
} else {
try {
ContextInitializer ctxInit = new ContextInitializer(loggerContext);
ctxInit.autoConfig();
} catch (JoranException je) {
StatusPrinter.print(loggerContext);
}
}
System.out.printf("Adding logger context: %s to map for context: %s\n", loggerContext.getName(), contextName);
contextMap.put(contextName, loggerContext);
}
return loggerContext;
}
}