You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ben Incani <be...@datacomit.com.au> on 2007/01/16 05:15:46 UTC

separate log files

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

RE: separate log files

Posted by Chris Hostetter <ho...@fucit.org>.
: 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: I'm glad you managed to get your situation working, but did you try
the instructions on the TomCat documentation page about configuring
seperate loggers per context?  if it didnt' work, did you try mailing the
tomcat user list?

what you have here is definitely a "kludge" as you say ... and not
something i would recommend in general ... for starters, it assumes there
will allways be a logging.properties file, besides the possibility that it
won't be there, this also doesn't play nicely with the
possibility of someone using the
java.util.logging.config.file or java.util.logging.config.class properties
... not to mention the fact that Servlet containers are totally within
thir right to control logging programaticly using the public LogManager
APIs based on configuration options from their own config files well
before any applications are initialized ... and this approach would undo
any of that configuration -- which could break the servlet contains own
logs not just the logging info from the individual webapps.


: <!--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 <be...@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
: >
: >
:



-Hoss


RE: separate log files

Posted by Ben Incani <be...@datacomit.com.au>.
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 <be...@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
> 
> 

Re: separate log files

Posted by Chris Hostetter <ho...@fucit.org>.
: 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 <be...@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


Re: separate log files

Posted by Yonik Seeley <yo...@apache.org>.
I wonder of jetty or tomcat can be configured to put logging output
for different webapps in different log files...

-Yonik

On 1/15/07, Ben Incani <be...@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