This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mwoodiupui/DS-1460
[DS-1460] Add SOLR logging config file
- Loading branch information
Showing
4 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
webapp/src/main/java/org/dspace/solr/filters/ConfigureLog4jListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters