but does this work in a multi-threaded environment?
if multiple requests are coming in on multiple threads, would it still
be accurate? Perhaps that depends on the underlying implementation?
adding the core to the MDC within a RequestHandler context seems
reasonable and minimally invasive.
ryan
On Dec 17, 2008, at 2:24 PM, Smiley, David W. wrote:
I propose that MDC or NDC be used instead. I prefer MDC. I've
written some server-side multi-threaded code where each Thread would
run a job and I wanted the job name in the logs.
http://www.slf4j.org/api/org/slf4j/MDC.html
At some early point when Solr receives a request, you simply store a
name-value pair which would be "core" and the name of the core for
us. In a finally block, remove it. In a log4j config file, in the
ConversionPattern, put this: %X{core} and this will expand to the
core name.
Some groovy snippet I wrote:
final MDC_KEY = "OraSeqId"
MDC.put(MDC_KEY, seq.id as String)//must be removed; see finally
//in-finally
MDC.remove(MDC_KEY)
~ David Smiley
On 12/17/08 2:17 PM, "Erik Hatcher" <e...@ehatchersolutions.com>
wrote:
On Dec 17, 2008, at 12:24 PM, Ryan McKinley wrote:
I'm not sure I understand...
are you suggesting that rather then configuring our logger like this:
static Logger log = LoggerFactory.getLogger(SolrCore.class);
We get the Logger everytime we use it with something like:
Logger log = LoggerFactory.getLogger(classname+":"+core.getName() );
That seems like a lot of overhead for marginal gain...
I'm not up on the logging tips and tricks best practices these days,
but yeah, I was suggesting something like that. There's no rule that
says logging keys be FQCNs.... that's a decent convention for most
cases with a package structure that is well organized and filterable.
In this case having the core name in there as a prefix makes a lot of
sense to me.
We could provide a LoggerUtils.getLogger(core, clazz) or something
like to keep it DRY and consistent.
Erik