You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by deepak singh <de...@gmail.com> on 2009/06/15 14:11:22 UTC

Issue with using NDC (nested diagnostic contexts)

Hi,
  I am using NDC (*nested diagnostic contexts*) for appending the text from
a specific thread.
  Using floowing code:

-------------------------
 //In side the run method of that thread
  log4cxx::NDC::push("Thread specific Info");

  printing some log4cxx messages.......

 //Just before exiting the thread
 log4cxx::NDC::pop();
-------------------------------

But the issue is I am not able to get the "Thread specific Info" message in
any of the messages I am printing in that thread.
I am using log4cxx 0.10.0 version.
Please let me know if you have any idea.

Thanks
Deepak

Re: Issue with using NDC (nested diagnostic contexts)

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
On 2009-06-15 06:16, deepak singh wrote:
> On Mon, Jun 15, 2009 at 5:43 PM, Assaf Lavie <as...@gmail.com> wrote:
>> On Mon, Jun 15, 2009 at 3:11 PM, deepak singh <de...@gmail.com>wrote:
>>>   I am using NDC (*nested diagnostic contexts*) for appending the text
>>> from a specific thread.

>>> But the issue is I am not able to get the "Thread specific Info" message
>>> in any of the messages I am printing in that thread.
 >>>
 >> What format pattern are you using?
 >>
 >   log4cxx::LayoutPtr layoutPtr(new log4cxx::PatternLayout("%c-%p (%d{dd MMM
 > yyyy HH:mm:ss}) [%-5t] %m%n"));

Your pattern layout does not include the conversion character to indicate where 
you want your NDC stack to be inserted:

x - Used to output the NDC (nested diagnostic context) associated with the 
thread that generated the logging event. (From the PatternLayout documentation.)

"%c-%p (%d{dd MMM yyyy HH:mm:ss}) [%-5t] %x %m%n"

That change should fix your output issue and then you can start playing more 
with placement (or use at all) of the NDC::push/NDC::pop methods and see where 
they work best for you. I prefer to use the constructor to set the value and let 
stack scope take care of the pop.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

Re: Issue with using NDC (nested diagnostic contexts)

Posted by deepak singh <de...@gmail.com>.
I am using following format.

  //log4cxx initialization
  log4cxx::LogManager::resetConfiguration();
  log4cxx::LayoutPtr layoutPtr(new log4cxx::PatternLayout("%c-%p (%d{dd MMM
yyyy HH:mm:ss}) [%-5t] %m%n"));
  log4cxx::AppenderPtr appenderPtr( new log4cxx::ConsoleAppender(layoutPtr,
"System.err"));
  log4cxx::BasicConfigurator::configure(appenderPtr);
Thanks
Deepak

On Mon, Jun 15, 2009 at 5:43 PM, Assaf Lavie <as...@gmail.com> wrote:

> What format pattern are you using?
>
>
> On Mon, Jun 15, 2009 at 3:11 PM, deepak singh <de...@gmail.com>wrote:
>
>> Hi,
>>   I am using NDC (*nested diagnostic contexts*) for appending the text
>> from a specific thread.
>>   Using floowing code:
>>
>> -------------------------
>>  //In side the run method of that thread
>>   log4cxx::NDC::push("Thread specific Info");
>>
>>   printing some log4cxx messages.......
>>
>>  //Just before exiting the thread
>>  log4cxx::NDC::pop();
>> -------------------------------
>>
>> But the issue is I am not able to get the "Thread specific Info" message
>> in any of the messages I am printing in that thread.
>> I am using log4cxx 0.10.0 version.
>> Please let me know if you have any idea.
>>
>> Thanks
>> Deepak
>>
>>
>
>

Re: Issue with using NDC (nested diagnostic contexts)

Posted by Assaf Lavie <as...@gmail.com>.
What format pattern are you using?

On Mon, Jun 15, 2009 at 3:11 PM, deepak singh <de...@gmail.com> wrote:

> Hi,
>   I am using NDC (*nested diagnostic contexts*) for appending the text
> from a specific thread.
>   Using floowing code:
>
> -------------------------
>  //In side the run method of that thread
>   log4cxx::NDC::push("Thread specific Info");
>
>   printing some log4cxx messages.......
>
>  //Just before exiting the thread
>  log4cxx::NDC::pop();
> -------------------------------
>
> But the issue is I am not able to get the "Thread specific Info" message in
> any of the messages I am printing in that thread.
> I am using log4cxx 0.10.0 version.
> Please let me know if you have any idea.
>
> Thanks
> Deepak
>
>