lucene-solr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Incani" <ben.inc...@datacomit.com.au>
Subject RE: separate log files
Date Fri, 19 Jan 2007 03:01:24 GMT
Hi Solr devs,

I'm running multiple instances of Solr, which all using the same war
file to load from.  To log to separate files I implemented the following
kludge.

-Ben

<!--start SolrServlet.java.diff-->
23d22
< import org.apache.solr.request.SolrQueryResponse;
24a24
> import org.apache.solr.request.SolrQueryResponse;
33a34,36
> 
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
34a38,39
> import java.io.InputStream;
> import java.io.OutputStream;
35a41,42
> import java.util.Properties;
> import java.util.logging.LogManager;
47a55,80
>   /*
>    * switch java.util.logging.Logger appenders
>    *
>    * Add the following to the web context file
>    * <Environment name="solr/log-prefix" type="java.lang.String"
value="log-prefix." override="false" />
>    */
> 	private void switchAppenders(String prefix) {
> 		String logParam = "org.apache.juli.FileHandler.prefix";
> 		log.info("switching appender to " + logParam + "=" +
prefix);		
> 		Properties props = new Properties();
> 		try {
> 			InputStream configStream =
getClass().getResourceAsStream("/logging.properties");
> 			props.load(configStream);
> 			configStream.close();
> 			props.setProperty(logParam, prefix);
> 			ByteArrayOutputStream os = new
ByteArrayOutputStream();
> 			props.store((OutputStream)os, "LOGGING
PROPERTIES"); 
> 			LogManager.getLogManager().readConfiguration(new
ByteArrayInputStream(os.toByteArray())); 		
> 			log.info("props: " + props.toString());
> 		}
> 		catch(Exception e) {
> 			String errMsg = "Error: Cannot load
configuration file; Cause: " + e.getMessage();
> 			log.info(errMsg);
> 		}
> 	}
>   
48a82
> 	  
52c86,91
< 
---
>       
>       // change the logging properties
>       String prefix =
(String)c.lookup("java:comp/env/solr/log-prefix");
>       if (prefix!=null)
>    		  switchAppenders(prefix);  
>       
64a104
>        
<!--end SolrServlet.java.diff-->


> -----Original Message-----
> From: Chris Hostetter [mailto:hossman_lucene@fucit.org] 
> Sent: Wednesday, 17 January 2007 6:04 AM
> To: solr-user@lucene.apache.org
> Subject: Re: separate log files
> 
> 
> : I wonder of jetty or tomcat can be configured to put logging output
> : for different webapps in different log files...
> 
> i've never tried it, but the tomcat docs do talk about tomcat 
> providing a custom implimentation of java.util.logging 
> specificly for this purpose.
> 
> Ben: please take a look at this doc...
> 
> http://tomcat.apache.org/tomcat-5.5-doc/logging.html
> 
> ..specifically the section on java.util.logging (since that's 
> what Solr
> uses) ... I believe you'll want something like the "Example 
> logging.properties file to be placed in common/classes" so 
> that you can control the logging.
> 
> Please let us all know if this works for you ... it would 
> make a great addition to the SolrTomcat wiki page.
> 
> 
> : On 1/15/07, Ben Incani <ben.incani@datacomit.com.au> wrote:
> : > Hi Solr users,
> : >
> : > I'm running multiple instances of Solr, which all using 
> the same war
> : > file to load from.
> : >
> : > Below is an example of the servlet context file used for each
> : > application.
> : >
> : > <Context path="/app1-solr" docBase="/var/usr/solr/solr-1.0.war"
> : > debug="0" crossContext="true" >
> : >         <Environment name="solr/home" type="java.lang.String"
> : > value="/var/local/app1" override="true" />
> : > </Context>
> : >
> : > Hence each application is using the same
> : > WEB-INF/classes/logging.properties file to configure logging.
> : >
> : > I would like to each instance to log to separate log 
> files such as;
> : >         app1-solr.yyyy-mm-dd.log
> : >         app2-solr.yyyy-mm-dd.log
> : >         ...
> : >
> : > Is there an easy way to append the context path to
> : > org.apache.juli.FileHandler.prefix
> : > E.g.
> : > org.apache.juli.FileHandler.prefix = ${catalina.context}-solr.
> : >
> : > Or would this require a code change?
> : >
> : > Regards
> : >
> : > -Ben
> :
> 
> 
> 
> -Hoss
> 
> 

Mime
View raw message