Programmatically configuring SLF4J for Solr 1.4?

View: New views
4 Messages — Rating Filter:   Alert me  

Programmatically configuring SLF4J for Solr 1.4?

by Don Werve-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So, I've spent a bit of the day banging my head against this, and can't get
it sorted.  I'm using a DirectSolrConnection embedded in a JRuby
application, and everything works great, except I can't seem to get it to do
anything except log to the console.  I've tried pointing
'java.util.logging.config.file' to a properties file, as well as specifying
a logfile as part of the constructor for DirectSolrConnection, but so far,
nothing has really worked.

What I'd like to do is programmatically direct the Solr logs to a logfile,
so that I can have my app start up, parse its config, and throw the Solr
logs where they need to go based on that.

So, I don't suppose anybody has a code snippet (in Java) that sets up SLF4J
for Solr logging (and that doesn't reference an external properties file)?

Using the latest (1 Nov 2009) nightly build of Solr 1.4.0-dev

Re: Programmatically configuring SLF4J for Solr 1.4?

by ryantxu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm sure it is possible to configure JDK logging (java.util.loging)  
programatically... but I have never had much luck with it.

It is very easy to configure log4j programatically, and this works  
great with solr.

To use log4j rather then JDK logging, simply add slf4j-
log4j12-1.5.8.jar (from http://www.slf4j.org/download.html) to your  
classpath

ryan



On Nov 1, 2009, at 11:05 PM, Don Werve wrote:

> So, I've spent a bit of the day banging my head against this, and  
> can't get
> it sorted.  I'm using a DirectSolrConnection embedded in a JRuby
> application, and everything works great, except I can't seem to get  
> it to do
> anything except log to the console.  I've tried pointing
> 'java.util.logging.config.file' to a properties file, as well as  
> specifying
> a logfile as part of the constructor for DirectSolrConnection, but  
> so far,
> nothing has really worked.
>
> What I'd like to do is programmatically direct the Solr logs to a  
> logfile,
> so that I can have my app start up, parse its config, and throw the  
> Solr
> logs where they need to go based on that.
>
> So, I don't suppose anybody has a code snippet (in Java) that sets  
> up SLF4J
> for Solr logging (and that doesn't reference an external properties  
> file)?
>
> Using the latest (1 Nov 2009) nightly build of Solr 1.4.0-dev


Re: Programmatically configuring SLF4J for Solr 1.4?

by Don Werve-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/1 Ryan McKinley <ryantxu@...>

> I'm sure it is possible to configure JDK logging (java.util.loging)
> programatically... but I have never had much luck with it.
>
> It is very easy to configure log4j programatically, and this works great
> with solr.
>

Don't suppose I could trouble you for an example?  I'm not terribly familiar
with Java logging frameworks just yet.

Re: Programmatically configuring SLF4J for Solr 1.4?

by hossman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

: it sorted.  I'm using a DirectSolrConnection embedded in a JRuby
: application, and everything works great, except I can't seem to get it to do
: anything except log to the console.  I've tried pointing
: 'java.util.logging.config.file' to a properties file, as well as specifying

how have you tried pointing it at a properties file?

it's a system property that needs to be set before tany code attempts to
load any of the logging related classes, so in JRuby you may have to do
soemthing special to specify it before JRUby loads the JVM (normally it
can only be set on the command line when executing java,
System.setProperty doesn't work (in any JVM)

worst case scenerio, you can modify the default logging.properties file
that is in the JVM JRuby runs.

: What I'd like to do is programmatically direct the Solr logs to a logfile,
: so that I can have my app start up, parse its config, and throw the Solr
: logs where they need to go based on that.
:
: So, I don't suppose anybody has a code snippet (in Java) that sets up SLF4J
: for Solr logging (and that doesn't reference an external properties file)?

SLF4J is just a proxy API, it doesn't know anything baout log files or log
levels or log filtering ... you can programaticly change the JUL Logging
using the LogManager API...

http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/LogManager.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/LogManager.html#getLogger(java.lang.String)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/Logger.html#addHandler(java.util.logging.Handler)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/FileHandler.html



-Hoss