Example #1
0
  /** Copies a well known style out to the data directory and adds a catalog entry for it. */
  void initializeStyle(Catalog catalog, String styleName, String sld) throws IOException {

    // copy the file out to the data directory if necessary
    if (resourceLoader.find("styles", sld) == null) {
      FileUtils.copyURLToFile(
          GeoServerLoader.class.getResource(sld),
          new File(resourceLoader.findOrCreateDirectory("styles"), sld));
    }

    // create a style for it
    StyleInfo s = catalog.getFactory().createStyle();
    s.setName(styleName);
    s.setFilename(sld);
    catalog.add(s);
  }
Example #2
0
  public static void configureGeoServerLogging(
      GeoServerResourceLoader loader,
      InputStream loggingConfigStream,
      boolean suppressStdOutLogging,
      boolean suppressFileLogging,
      String logFileName)
      throws FileNotFoundException, IOException, ConfigurationException {
    // JD: before we wipe out the logging configuration, save any appenders that are not
    // console or file based. This allows for other types of appenders to remain in tact
    // when geoserver is reloaded.
    List<Appender> appenders = new ArrayList();
    Enumeration a = LogManager.getRootLogger().getAllAppenders();
    while (a.hasMoreElements()) {
      Appender appender = (Appender) a.nextElement();
      if (!(appender instanceof ConsoleAppender || appender instanceof FileAppender)) {
        // save it
        appenders.add(appender);
      }
    }

    Properties lprops = new Properties();
    lprops.load(loggingConfigStream);
    LogManager.resetConfiguration();
    //        LogLog.setQuietMode(true);
    PropertyConfigurator.configure(lprops);
    //        LogLog.setQuietMode(false);

    // configuring the log4j file logger
    if (!suppressFileLogging) {
      Appender gslf = org.apache.log4j.Logger.getRootLogger().getAppender("geoserverlogfile");
      if (gslf instanceof org.apache.log4j.FileAppender) {
        if (logFileName == null) {
          logFileName =
              new File(loader.findOrCreateDirectory("logs"), "geoserver.log").getAbsolutePath();
        } else {
          if (!new File(logFileName).isAbsolute()) {
            logFileName = new File(loader.getBaseDirectory(), logFileName).getAbsolutePath();
            LoggingInitializer.LOGGER.fine(
                "Non-absolute pathname detected for logfile.  Setting logfile relative to data dir.");
          }
        }
        lprops.setProperty("log4j.appender.geoserverlogfile.File", logFileName);
        PropertyConfigurator.configure(lprops);
        LoggingInitializer.LOGGER.fine("Logging output to file '" + logFileName + "'");
      } else if (gslf != null) {
        LoggingInitializer.LOGGER.warning(
            "'log4j.appender.geoserverlogfile' appender is defined, but isn't a FileAppender.  GeoServer won't control the file-based logging.");
      } else {
        LoggingInitializer.LOGGER.warning(
            "'log4j.appender.geoserverlogfile' appender isn't defined.  GeoServer won't control the file-based logging.");
      }
    }

    // ... and the std output logging too
    if (suppressStdOutLogging) {
      LoggingInitializer.LOGGER.info(
          "Suppressing StdOut logging.  If you want to see GeoServer logs, be sure to look in '"
              + logFileName
              + "'");
      Enumeration allAppenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
      Appender curApp;
      while (allAppenders.hasMoreElements()) {
        curApp = (Appender) allAppenders.nextElement();
        if (curApp instanceof org.apache.log4j.ConsoleAppender) {
          org.apache.log4j.Logger.getRootLogger().removeAppender(curApp);
        }
      }
    }

    // add the appenders we saved above
    for (Appender appender : appenders) {
      LogManager.getRootLogger().addAppender(appender);
    }
    LoggingInitializer.LOGGER.fine(
        "FINISHED CONFIGURING GEOSERVER LOGGING -------------------------");
  }