logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Instance logging
Date Fri, 14 Nov 2003 14:44:31 GMT

Howdy,
I'm sorry I don't have too much time to spend on this.  It belongs on
the log4j-user and not log4j-dev mailing list anyways: you might get
more help there.

But it boils down to this: you can use whatever name you want for
loggers.  Most people just use the class name, which means the same
logger is shared by all instances of the class.  You don't want that
apparently.  So you have to name your loggers with the some instance
information, e.g. "device1".  If you know in advance how you're going to
name the loggers, you can pre-configure stuff for them in the log4j
configuration files.  If you don't know in advance, you have to have a
reference to the logger or the instance of class A that you want to log,
so you have to keep this reference somewhere yourself e.g. in a
singleton containing a list of all class A instances.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Sahraei Sasan-ssahra01 [mailto:sasan.sahraei@motorola.com]
>Sent: Friday, November 14, 2003 9:13 AM
>To: 'Log4J Developers List'
>Subject: RE: Instance logging
>
>Lets look at it this way,
>
>class A can be initialized with different params.
>
>say then we will have running instances of A like
>
>A(device1)
>
>A(device2)
>
>A(device3)
>
>etc,
>
>so the class type is the same but it has only initilized with different
>params, so how can I give it different loggers , even if I initialize
>loggers depending on e.g. device1, device2, etc these names can not be
>known during coding and I have to be able to change the loggin level
during
>run time.
>
>btw, please keep in mind that I am pretty new in using log4j , I'm
still
>kind of confused as how the inheritance will work in here and how can I
>create different catagories of loggers.
>
>-----Original Message-----
>From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com]
>Sent: 14 November 2003 14:06
>To: Log4J Developers List
>Subject: RE: Instance logging
>
>
>
>Howdy,
>You would have to use different logger names for the different forms.
>Either with a hashcode based approach or by just assigning them names,
>e.g. "loggerForDevice1" and "loggerForDevice2".  But it sound like you
>might also just want to make them different classes (probably
subclasses
>of a common parent).
>
>Yoav Shapira
>Millennium ChemInformatics
>
>
>>-----Original Message-----
>>From: Sahraei Sasan-ssahra01 [mailto:sasan.sahraei@motorola.com]
>>Sent: Friday, November 14, 2003 8:59 AM
>>To: 'Log4J Developers List'
>>Subject: RE: Instance logging
>>
>>I want to change the logging level while instances of the same class
>are
>>running, so this makes it difficult as how do I know that is the
output
>of
>>
>>getClass() + String.valueOf(hashCode())
>>
>>because I want to change the level from the log4j.properties.
>>
>>What I want to know if, say, multiple forms (of the same class type)
>are
>>running to monitor different devices, let's say one them is behaving
>>strange, so I need to change the debug level of only that one.
>>
>>S.
>>
>>
>>-----Original Message-----
>>From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com]
>>Sent: 14 November 2003 13:53
>>To: Log4J Developers List
>>Subject: RE: Instance logging
>>
>>
>>
>>Howdy,
>>You can't if you associate the logger with the class rather than the
>>instance, which is what most people do.  Most people do something
like:
>>private static final Logger LOGGER =
Logger.getLogger(ThisClass.class);
>>
>>In that case all instances of ThisClass at runtime share the same
>>logger.  However, there's nothing to prevent you from having different
>>loggers for each instance.  For example, you could do:
>>
>>private Logger logger;
>>
>>public ThisClass() {
>>  logger = Logger.getLogger(getClass() + String.valueOf(hashCode());
>>}
>>
>>Then you can individually modify the level for the Logger if you're
>>given the ThisClass object.
>>
>>But this is kind of unusual, why do you want to do it?
>>
>>Yoav Shapira
>>Millennium ChemInformatics
>>
>>
>>>-----Original Message-----
>>>From: Sahraei Sasan-ssahra01 [mailto:sasan.sahraei@motorola.com]
>>>Sent: Friday, November 14, 2003 8:49 AM
>>>To: 'Log4J Developers List'
>>>Subject: Instance logging
>>>
>>>Hi,
>>>
>>>A question about log4j. Is I create a category of logging for a class
>>type
>>>and during run time if multiple instances of that class are running
>and
>>I
>>>just want to change the logging level for only one running instance
of
>>that
>>>class type, what would be the way?
>>>
>>>Thanks,
>>>S.
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>>
>>
>>
>>
>>This e-mail, including any attachments, is a confidential business
>>communication, and may contain information that is confidential,
>>proprietary and/or privileged.  This e-mail is intended only for the
>>individual(s) to whom it is addressed, and may not be saved, copied,
>>printed, disclosed or used by anyone else.  If you are not the(an)
>intended
>>recipient, please immediately delete this e-mail from your computer
>system
>>and notify the sender.  Thank you.
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>
>
>
>
>This e-mail, including any attachments, is a confidential business
>communication, and may contain information that is confidential,
>proprietary and/or privileged.  This e-mail is intended only for the
>individual(s) to whom it is addressed, and may not be saved, copied,
>printed, disclosed or used by anyone else.  If you are not the(an)
intended
>recipient, please immediately delete this e-mail from your computer
system
>and notify the sender.  Thank you.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


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


Mime
View raw message