<commit_before>/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * 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 org.springframework.web.util;

import java.io.FileNotFoundException;

import javax.servlet.ServletContext;

import org.springframework.util.Log4jConfigurer;

/**
 * Convenience class that performs custom Log4J initialization for web environments,
 * supporting 2 init parameters at the servlet context level (i.e. context-param
 * in web.xml):
 * <ul>
 * <li>"log4jConfigLocation": name of the Log4J config file (relative to the web
 * application root directory, e.g. "WEB-INF/log4j.properties");
 * <li>"log4jRefreshInterval": interval between config file refresh* checks, in
 * milliseconds. If unspecified, a value of {@link Log4jConfigurer#DEFAULT_REFRESH_INTERVAL}
 * will be used.
 * </ul>
 *
 * <p>Note: initLogging should be called before any other Spring activity (when using
 * Log4J), to guarantee proper initialization before any Spring logging attempts.
 *
 * <p>Note: Sets the web app root system property, for "${key}" substitutions
 * within log file locations in the Log4J config file. The default system property
 * key is "webapp.root". Example, using context-param "webAppRootKey" = "demo.root":
 * log4j.appender.myfile.File=${demo.root}/WEB-INF/demo.log
 *
 * <p><b>WARNING</b>: Some containers like Tomcat do NOT keep system properties separate
 * per web app. You have to use unique "webAppRootKey" context-params per web app
 * then, to avoid clashes. Other containers like Resin do isolate each web app's
 * system properties: Here you can use the default key (i.e. no "webAppRootKey"
 * context-param at all) without worrying.
 *
 * <p><b>WARNING</b>: The WAR file containing the web application needs to be expanded
 * to allow for setting the web app root system property and for loading Log4J
 * configuration from a custom location. This is by default not the case when a
 * WAR file gets deployed to WebLogic, for example. Do not use this configurer
 * respectively Log4jConfigListener or Log4jConfigServlet in such an environment!
 *
 * @author <NAME>
 * @since 12.08.2003
 * @see org.springframework.util.Log4jConfigurer
 * @see Log4jConfigListener
 * @see Log4jConfigServlet
 */
public abstract class Log4jWebConfigurer {

	/** Parameter specifying the location of the Log4J config file */
	public static final String CONFIG_LOCATION_PARAM = "log4jConfigLocation";

	/** Parameter specifying the refresh interval for checking the Log4J config file */
	public static final String REFRESH_INTERVAL_PARAM = "log4jRefreshInterval";

	public static void initLogging(ServletContext servletContext) {
		// set the web app root system property
		WebUtils.setWebAppRootSystemProperty(servletContext);

		// only perform custom Log4J initialization in case of a config file
		String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
		if (location != null) {<commit_msg>clarify JavaDocs<commit_after>/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * 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 org.springframework.web.util;

import java.io.FileNotFoundException;

import javax.servlet.ServletContext;

import org.springframework.util.Log4jConfigurer;

/**
 * Convenience class that performs custom Log4J initialization for web environments,
 * supporting 2 init parameters at the servlet context level (i.e. context-param
 * in web.xml):
 * <ul>
 * <li>"log4jConfigLocation": name of the Log4J config file (relative to the web
 * application root directory, e.g. "WEB-INF/log4j.properties");
 * <li>"log4jRefreshInterval": interval between config file refresh* checks, in
 * milliseconds. If unspecified, a value of {@link Log4jConfigurer#DEFAULT_REFRESH_INTERVAL}
 * will be used.
 * </ul>
 *
 * <p>Note: initLogging should be called before any other Spring activity (when using
 * Log4J), to guarantee proper initialization before any Spring logging attempts.
 *
 * <p>Note: Sets the web app root system property, for "${key}" substitutions
 * within log file locations in the Log4J config file. The default system property
 * key is "webapp.root". Example, using context-param "webAppRootKey" = "demo.root":
 * log4j.appender.myfile.File=${demo.root}/WEB-INF/demo.log
 *
 * <p><b>WARNING</b>: Some containers like Tomcat do NOT keep system properties separate
 * per web app. You have to use unique "webAppRootKey" context-params per web app
 * then, to avoid clashes. Other containers like Resin do isolate each web app's
 * system properties: Here you can use the default key (i.e. no "webAppRootKey"
 * context-param at all) without worrying.
 *
 * <p><b>WARNING</b>: The WAR file containing the web application needs to be expanded
 * to allow for setting the web app root system property and for loading Log4J
 * configuration from a custom location. This is by default not the case when a
 * WAR file gets deployed to WebLogic, for example. Do not use this configurer, 
 * Log4jConfigListener or Log4jConfigServlet in such an environment!
 *
 * @author <NAME>
 * @since 12.08.2003
 * @see org.springframework.util.Log4jConfigurer
 * @see Log4jConfigListener
 * @see Log4jConfigServlet
 */
public abstract class Log4jWebConfigurer {

	/** Parameter specifying the location of the Log4J config file */
	public static final String CONFIG_LOCATION_PARAM = "log4jConfigLocation";

	/** Parameter specifying the refresh interval for checking the Log4J config file */
	public static final String REFRESH_INTERVAL_PARAM = "log4jRefreshInterval";

	public static void initLogging(ServletContext servletContext) {
		// set the web app root system property
		WebUtils.setWebAppRootSystemProperty(servletContext);

		// only perform custom Log4J initialization in case of a config file
		String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
		if (location != null) {
{'fraction_non_alphanumeric': 0.07938114517061885, 'fraction_numerical': 0.012434933487565067, 'mean_word_length': 4.48968253968254, 'pattern_counts': {'":': 6, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2888582', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1835, 'n_words': 800}