You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Nuno Carvalho <nu...@www.hotpop.com> on 2003/02/19 23:04:59 UTC

NDC behaviour

Hi,

I think I still don't understand the NDC functionality.

Consider that I'm logging information from a Java Servlet. This servlet have several access simultaneously. I would like 
to have a logging information grouped by transactions (i.e. client).

Example:

[Client #12345]: User have entered the site
[Client #12345]: User is opening the image file
[Client #12345]: User is quitting the site
[Client #84937]: User have entered the site
[Client #84937]: User is opening the image file
[Client #84937]: User is quitting the site

On this case, even with too much concurrency the log information is grouped by client ID.

Isn't this a task for NDC ?

At the implementation I'm using:

When entering into the servlet: NDC.push("Client #"+ID);
When exiting the servlet: NDC.pop();

Unfortunally, I can't get the required behaviour.

Sometimes I get something like:

[Client #12345 Client #84937 Client #63545]: User have entered the site

Could someone give me a hint ?

Thanks in advance.

Regards,
   Nuno



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: NDC behaviour

Posted by peter riegersperger <ri...@subnet.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 19 February 2003 23:04, Nuno Carvalho wrote:
> Hi,
>
> I think I still don't understand the NDC functionality.
[...]
> Isn't this a task for NDC ?

somebody will give you a better explanation, but i think i remember that the 
ndc works like a stack?

try the mdc. it works great and is imo easier to use.


- -- 
|-
| peter riegersperger  <ri...@subnet.at>
|-
| ein windows switcher tagebuch:
| http://forum.subnet.at/viewforum.php?f=22
|-
| subnet
| platform for media art and experimental technologies
|-
| http://www.subnet.at/
|-
| muehlbacherhofweg 5 // 5020 salzburg // austria
|-
| fon/fax +43/662/842 897
|- 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+VMMiIMP39JYOy9IRAsWNAKDyjvfX0VQPq13ssXSNz00tkaeJWgCgnTm9
6XaicIwTNJFemSD6j2xj580=
=BKx4
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: NDC behaviour

Posted by Daniel Serodio <da...@checkforte.com.br>.
On Wed, 2003-02-19 at 19:04, Nuno Carvalho wrote:
> Hi,
> 
> I think I still don't understand the NDC functionality.
> 
> Consider that I'm logging information from a Java Servlet. This servlet have several access simultaneously. I would like 
> to have a logging information grouped by transactions (i.e. client).
> 
> Example:
> 
> [Client #12345]: User have entered the site
> [Client #12345]: User is opening the image file
> [Client #12345]: User is quitting the site
> [Client #84937]: User have entered the site
> [Client #84937]: User is opening the image file
> [Client #84937]: User is quitting the site
> 
> On this case, even with too much concurrency the log information is grouped by client ID.
> 
> Isn't this a task for NDC ?
> 
> At the implementation I'm using:
> 
> When entering into the servlet: NDC.push("Client #"+ID);
> When exiting the servlet: NDC.pop();
> 
> Unfortunally, I can't get the required behaviour.
> 
> Sometimes I get something like:
> 
> [Client #12345 Client #84937 Client #63545]: User have entered the site
> 
> Could someone give me a hint ?
> 
> Thanks in advance.
> 
> Regards,
>    Nuno

	Seems like you're push'ing more often than pop'ing. It's been a while
since I used servlets, but it will only work if every thread servers
only one client, since NDC is managed on a per-thread basis.
	Anyway, your log will be "marked" with the Client#, but the log entries
won't necessarely be grouped. eg:

[Client #12345]: User have entered the site
[Client #84937]: User have entered the site
[Client #12345]: User is opening the image file
[Client #12345]: User is quitting the site
[Client #84937]: User is opening the image file
[Client #84937]: User is quitting the site


-- 
Daniel Serodio <da...@checkforte.com.br>
CheckForte


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: NDC behaviour

Posted by Shorn Tolley <sh...@yahoo.co.uk>.
Hi Nuno,

With an NDC, the logging context (which is stored "per
thread") works like a stack (hence the "push", "pop"
terminology for the method names).

The type of problem you are seeing (extraneous entries
on the stack) is the general class of error related to
forgetting to "pop" the most recently "pushed" stack
entry.

For your specific example, you've said that you are
"popping" when you exit the method.  But are you sure
you have all the exits covered?  

You've said that you only get multiple NDC entries
"sometimes".  I would guess that you've forgotten to
code for exceptions.  If the code that proceesses the
HTTP call throws an exception, are you catching that
exception and rememberig to pop the client ID off of
the NDC stack?  (actually, a finally clause would be a
better way to do that, rather than catching exceptions
you don't know how to deal with)

I doubt that you actually want to nest client IDs, I
think you might find that using the MDC (Mapped
Diagnostic Context) is a better fit for your problem. 
MDC's are based on the map concept rather than the
stack concept.

As for grouping the log statements within a single
file, if you think about it for a second, that's not
possible (or at least, an extremeley bad idea; you'd
have to wait until the application finished before you
could write the log file).

One of the things I do is to use sed to filter only
the lines I am interested in when I am only interested
in a known context.

The best way to go about making use of large or
multiple production logs is to get comfortable with
some text processing tools and use those to do the leg
work involved with tracking down problems.

I use Unix tools like Korn shell, grep and sed to do
my log file related text processing (Cygwin can
provide you with these tools if you are stuck in a
Windows environment).  A good alternative might be to
use a script language such as Perl or Python (or even
better: Jython!).

Cheers,
Shorn.

 --- Nuno Carvalho <nu...@www.hotpop.com>
wrote: > Hi,
> 
> I think I still don't understand the NDC
> functionality.
> 
> Consider that I'm logging information from a Java
> Servlet. This servlet have several access
> simultaneously. I would like 
> to have a logging information grouped by
> transactions (i.e. client).
> 
> Example:
> 
> [Client #12345]: User have entered the site
> [Client #12345]: User is opening the image file
> [Client #12345]: User is quitting the site
> [Client #84937]: User have entered the site
> [Client #84937]: User is opening the image file
> [Client #84937]: User is quitting the site
> 
> On this case, even with too much concurrency the log
> information is grouped by client ID.
> 
> Isn't this a task for NDC ?
> 
> At the implementation I'm using:
> 
> When entering into the servlet: NDC.push("Client
> #"+ID);
> When exiting the servlet: NDC.pop();
> 
> Unfortunally, I can't get the required behaviour.
> 
> Sometimes I get something like:
> 
> [Client #12345 Client #84937 Client #63545]: User
> have entered the site
> 
> Could someone give me a hint ?
> 
> Thanks in advance.
> 
> Regards,
>    Nuno
> 
> 

http://mobile.yahoo.com.au - Yahoo! Mobile
- Exchange IMs with Messenger friends on your Telstra or Vodafone mobile phone.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org