Re: Request For Comments: Log2

From: Date: Mon, 14 Sep 2009 14:07:45 +0000
Subject: Re: Request For Comments: Log2
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-52824@lists.php.net to get a copy of this message
Re Brandon, Brandon Savage a écrit :
I think I understand. You want me to reimplement the Log factory pattern, which allows for the generation of objects but defers the instantiation of those objects to the method itself. Something like this: $log = Log2::('Database', $options); $log->addHandler('File', $options);
No, not a factory, because here we may want multiple loggers at the same time not just a single one, but yeah, you got the idea, my main concern was instanciating "adapters" directly and configuring them in a non-unified way (the $options array solves this). In your example, I would just maintain an array of handlers in the log class, and delegate to their log() method in Log::log(), for example: $log = new Log(); // here default handler is stdout/sderr aka console $log->setDefaultHandler('Database', $options); // we change it to db $log->addHandler('File', $options); // we add a file logger $log->addHandler('Mail', $options); // we add a mail logger* // will delegate to db, file and mail loggers $log->log('foo', Log::WARNING); Anyway, that's just a suggestion, i'm sure there's space for more ideas :)
I think this could be accomplished, and I think that the addition of a constructor to the subclasses would make this easier to do with varying options. Note that Log2 cannot be instantiated directly, as it contains abstract methods. Log itself contains abstract methods as well, but because PHP 4 did not have the keyword "abstract" they are simply defined as methods without anything in the body, meaning you wouldn't raise an error by instantiating Log directly.
Yeah sure. Cheers, -- David

« previous php.pear.dev (#52824) next »