note 107832 added to function.error-log

From: Date: Thu, 08 Mar 2012 09:24:17 +0000
Subject: note 107832 added to function.error-log
Groups: php.notes 
Request: Send a blank email to php-notes+get-186542@lists.php.net to get a copy of this message
For beginners here is an example that will let you add audit code through your program then choose which audits get logged. helps keep your code clean as you can add as many adit calls as you want and the configure deals with them <code> // binary values define ("AUDIT_NORMAL",1); // 00001 define ("AUDIT_DB_INSERT",2); // 00010 define ("AUDIT_DB_UPDATE",4); // 00100 define ("AUDIT_DB_EXTRACT",8); // 01000 define ("AUDIT_DB_DELETE",16); // 10000 // define some types of audit level define ("AUDIT_JUST_DB", AUDIT_DB_INSERT + AUDIT_DB_UPDATE + AUDIT_DB_EXTRACT + AUDIT_DB_DELETE); // 11110 define ("AUDIT_ALL",31); // all possible options // 11111 define ("AUDIT_LEVEL",AUDIT_JUST_DB);// Choose the audit level to user $GLOBALS["CODEX"]= Array(1 => "Normal", 2 => "DB_INSERT", 4 => "DB_UPDATE", 8 => "DB_EXTRACT", 16 => "DB_DELETE"); define ("LOG_PATH", "/temp/mylog"); /** * Add an audit to the log * * Some Constants Used * * $GLOBALS["CODEX"] is an array of short descriptions for each audit type so that the log reads better. * * * use and AND statement to compare the type of information you are wanting to audit and the level that you have told your program to record * * type, level * AUDIT_NORMAL & AUDIT_LEVEL = 00000 ie 00001 & 11110 === 00000 ( Do not log ) * AUDIT_DB_UPDATE & AUDIT_LEVEL = 00100 ie 00100 & 11110 === 00100 ( Add to log ) * AUDIT_DB_INSERT & AUDIT_LEVEL = 00010 ie 00010 & 11110 === 00010 ( Add to log ) * * So when you AND a interger with a MASK in this case the AUDIT_LEVEL * @access public * @author IrishAdo <irishado@hotmail.com> * @param String Class you were in * @param String Type of Audit information * @param String Message **/ public function __AddAudit($class, $typeof, $msg){ if ((AUDIT_LEVEL & $typeof)*1 === $typeof && AUDIT_LEVEL != AUDIT_NONE){ $path = LOG_PATH . date("Ymd.H") . ".audit.log"; $fp = fopen($path ,"a"); if($fp){ $usr = $_SESSION["name"]; $ip = $_SERVER["REMOTE_HOST"]; $file = $_SERVER["SCRIPT_NAME"]; fwrite($fp, "". $GLOBALS["CODEX"][$typeof]."\t" . Date("r") . "\t$ip\t$file\t$class\t$usr\t$msg\r\n"); fclose($fp); } else { print "Unable to write to file $path."; exit(); } } } </code> ---- Server IP: 69.147.83.197 Probable Submitter: 194.116.198.188 (proxied: 82.33.246.34) ---- Manual Page -- http://www.php.net/manual/en/function.error-log.php Edit -- https://master.php.net/note/edit/107832 Del: integrated -- https://master.php.net/note/delete/107832/integrated Del: useless -- https://master.php.net/note/delete/107832/useless Del: bad code -- https://master.php.net/note/delete/107832/bad+code Del: spam -- https://master.php.net/note/delete/107832/spam Del: non-english -- https://master.php.net/note/delete/107832/non-english Del: in docs -- https://master.php.net/note/delete/107832/in+docs Del: other reasons-- https://master.php.net/note/delete/107832 Reject -- https://master.php.net/note/reject/107832 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186542) next »