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 Chien Wei Tan <Ch...@calytrix.com> on 2001/08/15 08:08:02 UTC
newbie: How to distinguish log outputs from different instances of the same class?
Hi,
How would I use log4j to distinguish the log messages coming from different
instances of the same class?
Eg. MyClass m1 = new MyClass(); // output log messages to MyLog.log
MyClass m2 = new MyClass(); // output log messages to MyLog.log, and
MyOtherLog.log
MyClass m3 = new MyClass(); // output log messages to MyOtherLog.log
MyClass m4 = new MyClass(); // output log messages to MyOtherLog.log,
and MyLog.log
if the above classes output log messages to MyLog.log and MyOtherLog.log,
how can i differentiate from the log messages, which instance of MyClass is
the source?????
In addition, 1) if m1, m2, m3, m4 were all running from the same location,
2) and what if they were distributed and running from different
locations?
any help would be great,
chienwei
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: newbie: How to distinguish log outputs from different
instances of the same class?
Posted by Robert Leftwich <di...@ix.net.au>.
At 04:08 PM 15/08/2001, Chien Wei Tan wrote:
>Hi,
>
>How would I use log4j to distinguish the log messages coming from different
>instances of the same class?
>
>Eg. MyClass m1 = new MyClass(); // output log messages to MyLog.log
> MyClass m2 = new MyClass(); // output log messages to MyLog.log, and
>MyOtherLog.log
> MyClass m3 = new MyClass(); // output log messages to MyOtherLog.log
> MyClass m4 = new MyClass(); // output log messages to MyOtherLog.log,
>and MyLog.log
>
>
>if the above classes output log messages to MyLog.log and MyOtherLog.log,
>how can i differentiate from the log messages, which instance of MyClass is
>the source?????
>
>In addition, 1) if m1, m2, m3, m4 were all running from the same location,
> 2) and what if they were distributed and running from
> different
>locations?
What feature of the class distinguishes each instance (the default being
the address in memory).?
You could use an NDC to log that see the examples for usage of NDC's - in
particular SortAlgo.java) or prefix every log output with 'this', e.g.
logger.debug(this+"My message").
Does that help?
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org