There has to be something under a LGPL or BSD somewhere, but if there is I can’t find it. After looking for a PHP logging library, the two most likely candidates are log4php and PEAR::Log. One is under the Apache License Version 2.0, the other under the PHP License. Neither is compatible with the GPL, and hence the AGPL.

The only BSD licensed Logger was to be found as part of eZ components. This however is specifically PHP5, with no support for PHP4. Waiting a year or two for more PHP5 penetration is not really an option I care for ;-).

All other alternatives I’ve found are either too simple, or too restrictive (and there’s a handful of those – none recent, or in procedural, or with php3 file extensions…)

Iamsure probably has it right that in these circumstances its probably necessary to go spend a while rolling your own implementation – so that’s what I’m about to start doing. So after a little thought I’ve decided to name it the Lugnar PHP Logging Library. Loggers are fairly simple – they do one thing, and do it well – so the time input should be minimal. I’ll release it under the LGPL, and stuff it into Q-LIB for use in Quantum Star SE.

Now the logger needs to do a few things. log4php does this very well, but it takes 26 includes to do it (which seems a bit much for a small application). Basically I want to:

a) be able to set a Layout for the log message, i.e. html, plaintext, xml, various text formats, or just a simple array.

b) be able to set an Appender, i.e. a class to handle writing to a resource: file, database, echo, trigger_error(), and even email.

c) to be capable of adding, removing information fields at will. For example I might want to add a user_id and IP to certain log events.

d) it should be capable of auto-generating objects based on prebuilt config files. Make setup a lot easier for more complex loggers. For example I may want a logger to log the same event as an ArrayLayout to the Database Appender, AND a SimpleLayout to the Email Appender – both at once.

e) it should (perhaps obviously) need to differentiate between log levels, and be capable of ignoring log events we’re not interested in. For example I could define a logger with a log level of WARN to ignore all levels except WARN, ERROR and FATAL, i.e. INFO and DEBUG log events would not be logged or reported.

Although loggers appear complex, what they do is extremely simple. They take a message, add additional information, format it, and write it to a resource. Not exactly rocket science – which may explain why there are so few PHP loggers (anyone can throw together a few lines to do the same thing). Unfortunately I really need a configurable library – not a limited one file class that can’t be used for complex logging.

Related posts:

  1. Future Works