コード例 #1
0
  private void applyLog4jConfiguration(
      ConfigurableEnvironment environment, ServletContext servletContext) {

    String log4jConfigLocation = "classpath:log4j.properties";

    if (environment.containsProperty("logging.file")) {
      String location = environment.getProperty("logging.file");
      servletContext.log("Setting LOG_FILE: " + location);
      System.setProperty("LOG_FILE", location);
    } else if (environment.containsProperty("logging.path")) {
      String location = environment.getProperty("logging.path");
      servletContext.log("Setting LOG_PATH: " + location);
      System.setProperty("LOG_PATH", location);
    } else if (environment.containsProperty("logging.config")) {
      log4jConfigLocation = environment.getProperty("logging.config");
    }

    try {
      servletContext.log("Loading log4j config from location: " + log4jConfigLocation);
      Log4jConfigurer.initLogging(log4jConfigLocation);
    } catch (FileNotFoundException e) {
      servletContext.log("Error loading log4j config from location: " + log4jConfigLocation, e);
    }

    MDC.put("context", servletContext.getContextPath());
  }
コード例 #2
0
 private void applySpringProfiles(
     ConfigurableEnvironment environment, ServletContext servletContext) {
   if (environment.containsProperty("spring_profiles")) {
     String profiles = environment.getProperty("spring_profiles");
     servletContext.log("Setting active profiles: " + profiles);
     environment.setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles));
   }
 }