elepha.info

Logging class for php5

11. 09. 06.

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.

 1: // We need to create instance of Log
 2: $log = new Log(new LogWriter("test", dirname(__FILE__).'/'));
 3: // Some action just passed and we want to log only a notice of something.
 4: // Functions as logError, logWarn and logFatal are also available
 5: $log->logNotice("testing notice text");
 6: // For another example we'll generate a random number from 0 to 5
 7: $no = rand(0, 5);
 8: // We record action time
 9: $log->recordActionTime('testing action');
10: sleep($no);
11: // Stop recording action time
12: $log->stopActionTime('testing action');
13: // And after all anytime when necessary we log `fatal` for `testing action`
14: $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

Submit a comment

Author info

Comment

You can respond to comment by writing [commentno] where commentno is number of comment displayed near author's name. Formatting is one of the easiest parts **text** will result in text, *text* will result into text and "Google":[http://www.google.com] will be formated into Google. No (X)HTML is allowed.


Browse by tags