All pastes #979586 Raw Edit

Loggin class ideas

public php v1 · immutable
·published 2008-04-10 13:32 UTC
rendered paste body
Log class A new way of doing Logging and debugging.			+----------+			| Keywords |			+----------+* Plugin based* Different output formats	- HTML toolbar	- javascript DOM	- File* Simple and advanced mode combined* Single method.* Altertive method if wanted* Extenable* Many configuration options* Code highligthing	- SQL 	- XML			+--------------+			| Sample usage |			+--------------+<?php//Loads predefined settings. Good for most usersinclude('logger/init.php');//Define the class. Basicly a wrapper function only$log = init_logger::init();//If you wan't to disable logging. Uncomment next line// $log->disable();//Now the $log object is ready to use.$sql = "SELECT * FROM news WHERE id='".$news_id."'";$news_item = $sql->query($sql);//Let's log a message with our query, along wiht the result.$log->log('info',"Running query to get news post",array('code'=>$sql,'code_lang'=>'sql','var'=>$news_item));//Let's do some profilling $log->log('info',"Profilling start...",array('profile'=>'test'));//Do some intensive task and log in betweenfor($t=0;$t<10;$t++) {sleep(1); $log->log('info',"Running calc...",array('profile'=>'test'));}//Let's stop the log$log->log('info',"Running calc...",array('profile'=>'test'));//Nothing keeps you from running multiple profiling at once. Just use a different profile keys (here 'test').//Bypass disabled logging$log->log('error','Bypassing disabled errorlogging',array('bypass'=>true));//You could also activate and deaktive the logging class if needed serveal times in row//Finally display your errors (if you have any!)$formatter = new Log_Format_HTML();//Set various settings for the formatter. This formatter will use HTML syntax. And is therefor well suited for emails and inline display$formatter->useJS(true);$output = new Log_Output_Email();$output->address('test@test.com');//Finnally send errors that might have occured to the email.$log->do($formatter,$output);