Re: Log->setIdent not behaving as I thought it would...
| From: | Jon Parise | Date: | Tue, 10 Jun 2003 00:36:40 +0000 |
| Subject: | Re: Log->setIdent not behaving as I thought it would... | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-17233@lists.php.net to get a copy of this message | ||
On Thu, Jun 05, 2003 at 05:34:09PM +1000, Alex Hayes wrote:
> Actually I think there is a problem in the composite implementation as well.
[..]
> Reason I say this is because when I run the following..
>
> $log = &Log::singleton('composite');
> $log_file = &Log::singleton('file', 'log.log', 'IDENT',
> $conf,PEAR_LOG_INFO);
> $log_mail = &Log::singleton('mail', 'me@myaddress.com',
> 'IDENT',
> $conf,PEAR_LOG_WARNING);
> $log->addChild($log_file);
> $log->addChild($log_mail);
>
> for ($i = 0; $i < 12; $i++) {
> $log->setIdent("ITEM".$i);
> $log->log("Foo: $i", $i);
> }
I see. You want the composite logger to change the ident string of
all of the composite's children.
Your solution of changing changing the composite's childrens' strings
directly, e.g.:
function setIdent($ident)
{
foreach ($this->_children as $id => $child) {
$this->_children[$id]->_ident = $ident;
}
}
... will work, but it introduces a side discussion. Imagine the case
where you have two composite loggers that share concrete log
instances.
$conf = array('mode' => 0600, 'timeFormat' => '%X %x');
$file = &Log::singleton('file', 'out.log', 'test', $conf);
$console = &Log::singleton('console', '', 'test');
$syslog = &Log::singleton('syslog', LOG_SYSLOG, 'test');
$comp1 = &Log::factory('composite');
$comp1->addChild($file);
$comp1->addChild($console);
$comp2 = &Log::factory('composite');
$comp2->addChild($file);
$comp2->addChild($syslog);
Calling $comp1->setIdent() will also affect the ident string printed
by $comp2's file logger because they share the same instance.
The "solution" here is to just create separate concrete log instances
for use by each composite, assuming that's what you want. I suppose
by calling $comp->setIdent(), you're truly indicating your desire to
change _all_ of the composite's loggers, too. Otherwise, you would
have just operated on the concrete instance that you wanted to change.
Given all of that, I think your solution is probably the most
consistent. I'll give it some more though later on and add a
setIdent() method to the Log_composite class if I can't think of any
more arguments against it.
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)