コード例 #1
0
  /**
   * Initialize logback, including setting the web app root system property.
   *
   * @param servletContext the current ServletContext
   * @see WebUtils#setWebAppRootSystemProperty
   */
  public static void initLogging(ServletContext servletContext) {
    // Expose the web app root system property.
    if (exposeWebAppRoot(servletContext)) {
      WebUtils.setWebAppRootSystemProperty(servletContext);
    }

    // Only perform custom logback initialization in case of a config file.
    String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    if (location != null) {
      // Perform actual logback initialization; else rely on logback's default initialization.
      try {
        // Return a URL (e.g. "classpath:" or "file:") as-is;
        // consider a plain file path as relative to the web application root directory.
        if (!ResourceUtils.isUrl(location)) {
          // Resolve system property placeholders before resolving real path.
          location = SystemPropertyUtils.resolvePlaceholders(location);
          location = WebUtils.getRealPath(servletContext, location);
        }

        // Write log message to server log.
        servletContext.log("Initializing logback from [" + location + "]");

        // Initialize without refresh check, i.e. without logback's watchdog thread.
        LogbackConfigurer.initLogging(location);

      } catch (FileNotFoundException ex) {
        throw new IllegalArgumentException(
            "Invalid 'logbackConfigLocation' parameter: " + ex.getMessage());
      }
    }
  }
コード例 #2
0
ファイル: ClassScaner.java プロジェクト: gitter-badger/wx_api
  public Set<Class> doScan(String basePackage) {
    Set<Class> classes = new HashSet<Class>();
    try {
      String packageSearchPath =
          ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
              + ClassUtils.convertClassNameToResourcePath(
                  SystemPropertyUtils.resolvePlaceholders(basePackage))
              + DEFAULT_RESOURCE_PATTERN;
      Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);

      for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        if (resource.isReadable()) {
          MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
          if ((includeFilters.size() == 0 && excludeFilters.size() == 0)
              || matches(metadataReader)) {
            try {
              classes.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
            } catch (ClassNotFoundException e) {
              e.printStackTrace();
            }
          }
        }
      }
    } catch (IOException ex) {
      throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
    }
    return classes;
  }
コード例 #3
0
 private File getLogFile(String location) throws FileNotFoundException {
   String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
   File file = ResourceUtils.getFile(resolvedLocation);
   if (!file.exists()) {
     throw new FileNotFoundException("Log file [" + resolvedLocation + "] not found");
   }
   return file;
 }
コード例 #4
0
  protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) {
    String name = element.getAttribute(NAME_ATTR);
    if (name.indexOf(' ') != -1) {
      logger.warn("Environment property name should not contain spaces: \"" + name + "\"");
    }

    String value = element.getAttribute(VALUE_ATTR);
    assembler.getBean().addConstructorArg(SystemPropertyUtils.resolvePlaceholders(value));
    super.postProcess(context, assembler, element);
  }
コード例 #5
0
 /**
  * Initialize logback from the given file location, with no config file refreshing. Assumes an XML
  * file in case of a ".xml" file extension, and a properties file otherwise.
  *
  * @param location the location of the config file: either a "classpath:" location (e.g.
  *     "classpath:mylogback.properties"), an absolute file URL (e.g. "file:C:/logback.properties),
  *     or a plain absolute path in the file system (e.g. " C:/logback.properties")
  * @throws FileNotFoundException if the location specifies an invalid file path
  */
 public static void initLogging(String location) throws FileNotFoundException {
   String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
   URL url = ResourceUtils.getURL(resolvedLocation);
   if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
     // DOMConfigurator.configure(url);
     configurator.setContext(lc);
     lc.reset();
     try {
       configurator.doConfigure(url);
     } catch (JoranException ex) {
       throw new FileNotFoundException(url.getPath());
     }
     lc.start();
   }
   // else {
   // PropertyConfigurator.configure(url);
   // }
 }
コード例 #6
0
 /**
  * Initialize logback from the given file.
  *
  * @param location the location of the config file: either a "classpath:" location (e.g.
  *     "classpath:logback.xml"), an absolute file URL (e.g. "file:C:/logback.xml), or a plain
  *     absolute path in the file system (e.g. "C:/logback.xml")
  * @throws java.io.FileNotFoundException if the location specifies an invalid file path
  */
 public static void initLogging(String location) throws FileNotFoundException, JoranException {
   String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
   URL url = ResourceUtils.getURL(resolvedLocation);
   initLogging(url);
 }