<commit_before>// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.enterprise.connector.servlet;

import com.google.common.base.Strings;
import com.google.enterprise.connector.common.PropertiesException;
import com.google.enterprise.connector.logging.NDC;
import com.google.enterprise.connector.manager.ConnectorManagerException;
import com.google.enterprise.connector.manager.Context;

import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Properties;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;

/**
 * <p>Admin servlet to set and fetch the logging {@link Level} for the
 * Connector Manager's Connector logs or Feed logs.
 * <p>
 * This servlet allows the user to alter the level of logging detail
 * dynamically, without restarting the Connector Manager.  More detailed
 * logs are especially useful when trying to troubleshoot connector problems.
 * <p>
 * Connector logs contain the status of the Connector Manager and all
 * Connector instances as they perform their various tasks.
 * Feed logs identify each document, and it associated meta-data, as
 * they are feed to the GSA.
 * <p>
 * The recognized logging levels in increasing levels of detail are:
 * <ul><li>{@code SEVERE} - Catastrophic failure; the Connector cannot continue
 *         running.</li>
 * <li>{@code WARNING} - Unexpected exceptional conditions, the product may
 *     not function properly.</li>
 * <li>{@code INFO} - Informational message. This is the default connector
 *     logging level upon installation.</li>
 * <li>{@code CONFIG} - Configuration details and higher product functions.</li>
 * <li>{@code FINE} - Generally information related to batches of documents.</li>
 * <li>{@code FINER} - Generally information related individual documents.</li>
 * <li>{@code FINEST} - Generally information related to document meta-data,
 *     processing detail that is exceptionally verbose.</li>
 * </ul>
 * <p>In addition to the above logging levels, the following psuedo-levels are
 * recognized:
 * <ul><li>{@code OFF} - Logging is turned off.  This is the default feed
 *         logging level upon installation.</li>
 * <li>{@code ALL} - Enable most detailed logging (alias of {@code FINEST}).</li>
 * </ul>
 * {@code ALL} and {@code OFF} are more conveniently used with feed logging,
 * which is currently an "all or nothing" style implementation.
 * <p>
 * After altering the desired logging level, allow the product to run for
 * the prescribed time (anywhere from several minutes to days).  Then the
 * {@link com.google.enterprise.connector.servlet.GetConnectorLogs GetConnectorLogs}
 * servlet may subsequently be used to fetch the accumulated log files for
 * analysis.
 *
 * <p><b>Usage:</b>
 * <br>To fetch the current connector logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/getConnectorLogLevel</pre>
 * </p>
 * <p>To set the connector logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setConnectorLogLevel?level=[level]</pre>
 * <br>where [level] is one of the previously defined logging levels.  Setting
 * the connector logging level to {@code INFO} restores it to the default
 * configuration.  Setting the connector logging level to {@code OFF} is
 * not recommended.
 * <p>For instance:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setConnectorLogLevel?level=ALL</pre>
 *
 * <p><br>To fetch the current feed logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/getFeedLogLevel</pre></p>
 *
 * <p>To set the feed logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setFeedLogLevel?level=[level]</pre>
 * <br>where [level] is one of the previously defined logging levels.  For
 * feed logs, the recommended levels are {@code OFF} and {@code ON} (or {@code ALL}).
 * <p>For instance:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setFeedLogLevel?level=ALL</pre>
 */
public class LogLevel extends HttpServlet {
  private static final Logger LOGGER =
      Logger.getLogger(LogLevel.class.getName());

  /**
   * Specialized {@code doTrace} method that constructs an XML representation
   * of the given request and returns it as the response.
   */
  @Override
  protected void doTrace(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    ServletDump.dumpServletRequest(req, res);
  }

  /**
   * Sets Logging levels for connectors and feeds.
   *
   * @param req
   * @param res
   * @throws IOException
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    doPost(req, res);
  }
<commit_msg>Fixed bug 4999318 by removing an invalid reference in the API doc to a logging level of ON.<commit_after>// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.enterprise.connector.servlet;

import com.google.common.base.Strings;
import com.google.enterprise.connector.common.PropertiesException;
import com.google.enterprise.connector.logging.NDC;
import com.google.enterprise.connector.manager.ConnectorManagerException;
import com.google.enterprise.connector.manager.Context;

import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Properties;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeansException;

/**
 * <p>Admin servlet to set and fetch the logging {@link Level} for the
 * Connector Manager's Connector logs or Feed logs.
 * <p>
 * This servlet allows the user to alter the level of logging detail
 * dynamically, without restarting the Connector Manager.  More detailed
 * logs are especially useful when trying to troubleshoot connector problems.
 * <p>
 * Connector logs contain the status of the Connector Manager and all
 * Connector instances as they perform their various tasks.
 * Feed logs identify each document, and it associated meta-data, as
 * they are feed to the GSA.
 * <p>
 * The recognized logging levels in increasing levels of detail are:
 * <ul><li>{@code SEVERE} - Catastrophic failure; the Connector cannot continue
 *         running.</li>
 * <li>{@code WARNING} - Unexpected exceptional conditions, the product may
 *     not function properly.</li>
 * <li>{@code INFO} - Informational message. This is the default connector
 *     logging level upon installation.</li>
 * <li>{@code CONFIG} - Configuration details and higher product functions.</li>
 * <li>{@code FINE} - Generally information related to batches of documents.</li>
 * <li>{@code FINER} - Generally information related individual documents.</li>
 * <li>{@code FINEST} - Generally information related to document meta-data,
 *     processing detail that is exceptionally verbose.</li>
 * </ul>
 * <p>In addition to the above logging levels, the following psuedo-levels are
 * recognized:
 * <ul><li>{@code OFF} - Logging is turned off.  This is the default feed
 *         logging level upon installation.</li>
 * <li>{@code ALL} - Enable most detailed logging (alias of {@code FINEST}).</li>
 * </ul>
 * {@code ALL} and {@code OFF} are more conveniently used with feed logging,
 * which is currently an "all or nothing" style implementation.
 * <p>
 * After altering the desired logging level, allow the product to run for
 * the prescribed time (anywhere from several minutes to days).  Then the
 * {@link com.google.enterprise.connector.servlet.GetConnectorLogs GetConnectorLogs}
 * servlet may subsequently be used to fetch the accumulated log files for
 * analysis.
 *
 * <p><b>Usage:</b>
 * <br>To fetch the current connector logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/getConnectorLogLevel</pre>
 * </p>
 * <p>To set the connector logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setConnectorLogLevel?level=[level]</pre>
 * <br>where [level] is one of the previously defined logging levels.  Setting
 * the connector logging level to {@code INFO} restores it to the default
 * configuration.  Setting the connector logging level to {@code OFF} is
 * not recommended.
 * <p>For instance:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setConnectorLogLevel?level=ALL</pre>
 *
 * <p><br>To fetch the current feed logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/getFeedLogLevel</pre></p>
 *
 * <p>To set the feed logging level:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setFeedLogLevel?level=[level]</pre>
 * <br>where [level] is one of the previously defined logging levels.  For
 * feed logs, the recommended levels are {@code OFF} and {@code ALL}.
 * <p>For instance:
 * <br><pre>  http://[cm_host_addr]/connector-manager/setFeedLogLevel?level=ALL</pre>
 */
public class LogLevel extends HttpServlet {
  private static final Logger LOGGER =
      Logger.getLogger(LogLevel.class.getName());

  /**
   * Specialized {@code doTrace} method that constructs an XML representation
   * of the given request and returns it as the response.
   */
  @Override
  protected void doTrace(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    ServletDump.dumpServletRequest(req, res);
  }

  /**
   * Sets Logging levels for connectors and feeds.
   *
   * @param req
   * @param res
   * @throws IOException
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException {
    doPost(req, res);
  }

{'fraction_non_alphanumeric': 0.10580389329488103, 'fraction_numerical': 0.002072819033886085, 'mean_word_length': 4.229500471253535, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6101766', 'n_tokens_mistral': 3051, 'n_tokens_neox': 3019, 'n_words': 1136}