• Next post: Cevro Inštitút
  • Previous post: Webddeveloper’s nightmare is over, new Mac is on the way!
  • Leave a Reply

Logging class for php5

posted on Monday, 11 September, 2006 at 12:14 am

The project I'm currently working on brings me many worries. One of them is the speed with which php is processed. I wrote today a class for logging events and computing microtime.

Currently its written for php5 but ill have to make php4 version as well because application is mainly for php4.

In 5 version it uses one interface. Together there are 2 classes, but the main one LogWriter can be used alone as well.

Because class is not documented I'll give u an example how to use it. Lets say we one to log one action and also we need to count how log another action lasted.

// We need to create instance of Log
$log = new Log(new LogWriter("test", dirname(__FILE__).'/'));
// Some action just passed and we want to log only a notice of something.
// Functions as logError, logWarn and logFatal are also available
$log->logNotice("testing notice text");
// For another example we'll generate a random number from 0 to 5
$no = rand(0, 5);
// We record action time
$log->recordActionTime('testing action');
sleep($no);
// Stop recording action time
$log->stopActionTime('testing action');
// And after all anytime when necessary we log `fatal` for `testing action`
$log->logFatalWithName('something fatal just happened at action', 'testing action');

The source codes (LogWriter class and iLog interface) as well as zip archive are free to download. Please consider it 0.1b version, more complex documentation with usage and with php4 version will be here soon.

If you have any ideas how to make something there better please share it in comments here. Thanks

Leave a Reply

Personal information
Body

All fields marked with * are required.