org.apache.log4j.helpers.Loader.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.apache.log4j.helpers.Loader.getResource()方法的一些代码示例,展示了Loader.getResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader.getResource()方法的具体详情如下:
包路径:org.apache.log4j.helpers.Loader
类名称:Loader
方法名:getResource

Loader.getResource介绍

[英]This method will search for resource in different places. The search order is as follows:

  1. Search for resource using the thread context class loader under Java2. If that fails, search for resource using the class loader that loaded this class (Loader). Under JDK 1.1, only the the class loader that loaded this class (Loader) is used.
  2. Try one last time with ClassLoader.getSystemResource(resource), that is is using the system class loader in JDK 1.2 and virtual machine's built-in class loader in JDK 1.1.
    [中]此方法将在不同的位置搜索resource。搜寻次序如下:
    1.使用Java2下的线程上下文类加载器搜索resource。如果失败,请使用加载该类的类加载器([$3$])搜索resource。在JDK1.1下,只使用加载该类的类加载器(Loader)。
    1.最后尝试使用ClassLoader.getSystemResource(resource),即使用JDK 1.2中的系统类加载器和JDK 1.1中的虚拟机内置类加载器。

代码示例

代码示例来源:origin: log4j/log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: apache/log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: apache-log4j/log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: org.apache.log4j/com.springsource.org.apache.log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: org.apache.activemq/activemq-all

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: org.apache/log4j

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 *  Get a resource by delegating to getResource(String).
 *  @param resource resource name
 *  @param clazz class, ignored.
 *  @return URL to resource or null.
 *  @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: org.jboss.logmanager/log4j-jboss-logmanager

/**
 * Get a resource by delegating to getResource(String).
 *
 * @param resource resource name
 * @param clazz    class, ignored.
 *
 * @return URL to resource or null.
 *
 * @deprecated as of 1.2.
 */
public static URL getResource(String resource, Class clazz) {
  return getResource(resource);
}

代码示例来源:origin: org.copper-engine/copper-monitoring-server

if (logProperty == null) {
  try {
    final URL resource = Loader.getResource(propertylocation);
    if (resource != null) {
      try {

代码示例来源:origin: mrsarm/log4jwebtracker

String file = getInitParameter("log4jConfigLocation");
if (file==null) {
  URL url = Loader.getResource("log4j.properties");
  if(new File(url.getFile()).exists()) {
    PropertyConfigurator.configure(url);
  } else {
    url = Loader.getResource("log4j.xml");
    if(new File(url.getFile()).exists()) {
      DOMConfigurator.configure(url);

代码示例来源:origin: org.jboss.ws/jbossws-common-tools

/**
* Returns true if a log4j configuration can be found given the current environment.
* See http://logging.apache.org/log4j/1.2/manual.html (Default Initialization Procedure)
* @return
*/
public static boolean isLog4jConfigurationAvailable()
{
 String log4jConfiguration = System.getProperty(LOG4J_CONFIGURATION);
 String resource = log4jConfiguration != null ? log4jConfiguration : LOG4J_PROPERTIES;
 URL url = null;
 try
 {
   url = new URL(resource);
   loadConfiguration(url);
 }
 catch (Exception e1)
 {
   try
   {
    url = Loader.getResource(resource);
    loadConfiguration(url);
   }
   catch (Exception e2)
   {
    //ignore
   }
 }
 return url != null;
}

代码示例来源:origin: apache/jena

URL url = Loader.getResource(resourceName) ;
if ( url != null ) {

代码示例来源:origin: org.apache.jena/jena-fuseki-core

URL url = Loader.getResource(resourceName) ;
if ( url != null ) {

代码示例来源:origin: com.netflix.blitz4j/blitz4j

URL url = Loader.getResource(LOG4J_PROPERTIES);
if (url != null) {
  try (InputStream in = url.openStream()) {

代码示例来源:origin: com.nesscomputing.components/ness-logging

public static URL configure(final String configurationName)
{
  final String log4jConfig = System.getProperty("log4j.configuration");
  if (log4jConfig != null) {
    // Log4j environment variable found, the LogManager will take care of
    // itself, don't bother reinitializing
    // This is what the LogManager does to find the resource.
    try {
      return new URL(log4jConfig);
    }
    catch (MalformedURLException mue) {
      return Loader.getResource(log4jConfig);
    }
  }
  final URL configFile = doConfigure(configurationName);
  LogManager.resetConfiguration();
  final Log log;
  if (configFile != null) {
    DOMConfigurator.configure(configFile);
    log = Log.findLog();
    log.info("Configured Logging for '%s', loading '%s'", configurationName, configFile);
  }
  else {
    BasicConfigurator.configure();
    log = Log.findLog();
    log.warn("Could not configure Logging for '%s', falling back to default!", configurationName == null ? "<unknown>" : configurationName);
  }
  return configFile;
}

代码示例来源:origin: apache/jena

@AfterClass public static void afterClassResetLogging() {
  // Unfortunately, this code "knows" how log4j was set up in testing
  // Thsi is fragile.
  URL configURL = Loader.getResource("log4j.properties");
  new PropertyConfigurator().doConfigure(configURL,
                      LogManager.getLoggerRepository());
}

相关文章