Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from mwoodiupui/DS-1460
Browse files Browse the repository at this point in the history
[DS-1460] Add SOLR logging config file
  • Loading branch information
mwoodiupui committed Jul 31, 2013
2 parents b244fc9 + 71468f6 commit bd02640
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 13 deletions.
37 changes: 32 additions & 5 deletions webapp/pom.xml
Expand Up @@ -69,7 +69,11 @@
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
<warSourceExcludes>WEB-INF/classes/**</warSourceExcludes>
<packagingExcludes>WEB-INF/classes/**</packagingExcludes>
<packagingExcludes>
WEB-INF/classes/**,
WEB-INF/lib/slf4j-jdk14-*.jar,
WEB-INF/lib/log4j-over-slf4j-*.jar
</packagingExcludes>
</configuration>
<goals>
<goal>war</goal>
Expand Down Expand Up @@ -109,11 +113,34 @@
<version>3.5.0</version>
<type>jar</type>
</dependency>
<!-- Commons Logging is needed for the LocalHostRestrictionFilter-->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>3.5.0</version>
</dependency>

<!-- Replace J.U.L. logging with log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
<type>jar</type>
<version>1.2.16</version>
</dependency>
</dependencies>

Expand Down
@@ -0,0 +1,86 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

package org.dspace.solr.filters;

import java.net.MalformedURLException;
import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Hierarchy;
import org.apache.log4j.Level;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.spi.Configurator;
import org.apache.log4j.spi.RootLogger;
import org.apache.log4j.xml.DOMConfigurator;

/**
* Initialize Log4J at application startup.
* This class mimics the default Log4J initialization procedure, except
* that it is controlled by context parameters rather than system properties.
*
* @author Mark H. Wood
*/
public class ConfigureLog4jListener
implements ServletContextListener
{
public void contextInitialized(ServletContextEvent sce)
{
ServletContext ctx = sce.getServletContext();

String logConfig = ctx.getInitParameter("log4j.configuration");
if (null == logConfig)
logConfig = "log4j.properties";

URL configURL;
try {
configURL = new URL(logConfig);
} catch (MalformedURLException e) {
configURL = Loader.getResource(logConfig);
}

if (null == configURL)
{
ctx.log("Log4J configuration not found. Left unconfigured.");
return;
}
else
{
ctx.log(" In context " + ctx.getContextPath() +
", configuring Log4J from " + configURL.toExternalForm());

String configuratorName = ctx.getInitParameter("log4j.configuratorClass");
if (null != configuratorName)
{
Configurator configurator;
try
{
configurator = (Configurator) Class.forName(configuratorName).newInstance();
} catch (Exception ex)
{
ctx.log("Unable to load custom Log4J configuration class '"
+ configuratorName + "': " + ex.getMessage());
return;
}

configurator.doConfigure(configURL, new Hierarchy(new RootLogger(Level.OFF)));
}
else if (configURL.getFile().endsWith(".xml"))
DOMConfigurator.configure(configURL);
else
PropertyConfigurator.configure(configURL);
}
}

public void contextDestroyed(ServletContextEvent sce)
{
// Nothing to be done
}
}
Expand Up @@ -16,17 +16,10 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LocalHostRestrictionFilter implements Filter {

private static Log log = LogFactory
.getLog(LocalHostRestrictionFilter.class);

private boolean enabled = true;

public LocalHostRestrictionFilter() {
Expand Down
12 changes: 11 additions & 1 deletion webapp/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -40,6 +40,12 @@
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->

<context-param>
<param-name>log4j.configuration</param-name>
<param-value>file://${dspace.dir}/config/log4j.properties</param-value>
<description>URL locating a Log4J configuration file (properties or XML).</description>
</context-param>

<!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
<filter>
Expand Down Expand Up @@ -99,7 +105,11 @@
</filter-mapping>

<!-- Otherwise it will continue to the old servlets -->


<listener>
<listener-class>org.dspace.solr.filters.ConfigureLog4jListener</listener-class>
</listener>

<servlet>
<servlet-name>SolrServer</servlet-name>
<display-name>Solr</display-name>
Expand Down

0 comments on commit bd02640

Please sign in to comment.