当前位置: 首页>>代码示例>>Java>>正文


Java Loader.getResource方法代码示例

本文整理汇总了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);
      } 
  }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:23,代码来源:LogFactory.java

示例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;
    }
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:41,代码来源:KonkerContextInitializer.java

示例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;
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:9,代码来源:KonkerContextInitializer.java

示例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);
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:10,代码来源:ContextJNDISelector.java

示例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;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:31,代码来源:ContextInitializer.java

示例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;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:8,代码来源:ContextInitializer.java

示例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));
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:12,代码来源:ContextInitializerTest.java

示例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));
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:12,代码来源:ContextInitializerTest.java

示例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
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:14,代码来源:ContextInitializerTest.java

示例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);
    }
}
 
开发者ID:bhits,项目名称:common-libraries,代码行数:51,代码来源:ImprovedAuditorFactory.java

示例11: getResource

import ch.qos.logback.core.util.Loader; //导入方法依赖的package包/类
private URL getResource(String filename, ClassLoader myClassLoader) {
    return Loader.getResource(filename, myClassLoader);
}
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:4,代码来源:StaticLoggerBinder.java

示例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;
	}
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:64,代码来源:LoggingContextSelector.java


注:本文中的ch.qos.logback.core.util.Loader.getResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。