Example #1
0
  public void start() {
    if (filename == null) {
      String tomcatHomeProperty = OptionHelper.getSystemProperty("catalina.home");

      filename = tomcatHomeProperty + File.separatorChar + DEFAULT_CONFIG_FILE;
      getStatusManager()
          .add(new InfoStatus("filename property not set. Assuming [" + filename + "]", this));
    }
    File configFile = new File(filename);
    if (configFile.exists()) {
      try {
        JoranConfigurator jc = new JoranConfigurator();
        jc.setContext(this);
        jc.doConfigure(filename);
      } catch (JoranException e) {
        // TODO can we do better than printing a stack trace on syserr?
        e.printStackTrace();
      }
    } else {
      getStatusManager().add(new WarnStatus("[" + filename + "] does not exist", this));
    }

    if (!quiet) {
      StatusPrinter.print(getStatusManager());
    }

    started = true;
  }
  // A few things that need to get set up before regular init().
  @Override
  protected void internalInit() {
    log.debug("Starting CWM Application Internal Init");
    log.debug("Application Class is " + getClass().getName());

    loadAppProperties();

    // If using Logback as the logger, and we have a logConfig property,
    // then read that configuration.
    File logConfig = configuration.getOptionalFile("cwm.logConfig");
    if (logConfig != null && LoggerFactory.getILoggerFactory() instanceof LoggerContext) {
      log.info("Log Configuration: {}", logConfig);
      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

      try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        // the context was probably already configured by default configuration rules
        lc.reset();
        configurator.doConfigure(logConfig);
      } catch (JoranException je) {
        je.printStackTrace();
      }
      StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
    }

    loadServices();

    getComponentInstantiationListeners()
        .add(new GuiceComponentInjector(this, getInjectionModuleArray()));

    super.internalInit();
  }
Example #3
0
  public void contextInitialized(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();

    String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);

    if (location != null) {
      try {
        servletContext.log("初始化 logback,配置文件[" + location + "]");
        initLogging(location);
      } catch (JoranException ex) {
        throw new IllegalArgumentException("无效'logbackConfigLocation'参数: " + ex.getMessage());
      }
    }
  }