Re: [PEPr] Proposal for Logging::Log4P
| From: | Michael Kahn | Date: | Sun, 18 Dec 2005 22:18:35 +0000 |
| Subject: | Re: [PEPr] Proposal for Logging::Log4P | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-40779@lists.php.net to get a copy of this message | ||
Hi Arnaud:
It's meant to be a container (as opposed to a handler) for the PEAR::Log framework, mainly as a convenience for sitewide logging, and kind of a PEAR::Log capable version of the PHP error_log() function. The main difference over PEAR::Log is you don't use factory methods to create and use a Log instance, you just make static method calls to the Log4P class. An ini-style configuration file controls what is logged and how--you can hook up several different logs (PEAR::Log instances) on a per-package or per-class basis.
There is a PHP port of the Apache Log4J project that is (unfortunately) also called log4p, and it is not the same as this. I've been using it too long to change the name though, unless it gets accepted as a PEAR package and this is a requirement. My main issue with the Log4J port is the reliance on a concrete instance, since you can't (at least as far as I am aware and as of this writing) do this in a PHP class def ...
class MyClass {
protected $log = LogFactory::getLog(__CLASS__);
}
... which is an essential way you hook in log4j (well, the way I do it through the Apache Commons Logging interface) in Java. Thus, for PHP I went with a static method approach, and the Log4P class takes care of managing log instances according to the calling class (I see $GLOBALS['log']->debug() type stuff in many codebases, and I don't like it!). Log4P uses a trick that I hope doesn't change in the PHP codebase: if you call a static method from within a PHP object instance, inside the static method $this will still be set to the calling instance. This makes the Log4P approach even easier than Java-style logging, since you can make logging into a one-liner, with no instance binding and configuration separate from your application code:
Log4P::debug($somedebugstatement);
Anyway, the Log4P package isn't meant to solve all the same problems as the PEAR::Log package, just a subset that is a common application of the Log class. I find it really convenient to use, and thought others might too.
Cheers,
Michael
Arnaud Limbourg wrote:
Michael Kahn wrote:Michael Kahn (http://pear.php.net/user/mkahn) proposes Logging::Log4P. You can find more detailed information here: http://pear.php.net/pepr/pepr-proposal-show.php?id=333Hi, I wonder if it is meant to be used on its own or as a PEAR::Log container ? Arnaud.