Revision: 62007
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 27, 2013 07:45 by COBOLdinosaur
Initial Code
<?php // first we declare a class to handle the file operations. class logfile{ function write($logString ) { if( $handle = @fopen( '../logs/actionLog.txt', 'a+' ) ) // this can be parameratized { $logString .="\n"; // insures each entry is on a new line fputs( $handle, $logString, strlen($logString) ); fclose( $handle ); return( true ); } else { return( false ); } } } // end logfile class function logAction($job,$cd,$msg) { // now we can create the custom code using the class $msgTypes=explode(',',"INFO,PROGRESS,WARN,ERROR,SECURITY,INVALID"); //invalid must always be the last entry ... add more if needed $cod = ($cd>=count($msgTypes)) ? (count($msgTypes) - 1) : $cd; // If the code is invalid return INVALID as the message type $dt=date("Y-m-d H:i:s"); // customize the date format to fit your requiremments $theLog = new logfile(); // an instance of the logfile class $msgStr=$msgTypes[$cod].'{'.$cd.'}: '.$job.': '.$dt.'>>> '.$msg; // create the log message $theLog->write($msgStr); // this fires the file handling in the class } ?>
Initial URL
http://coboldinosaur.com/pages/Custom_Logging_Site_Events.html
Initial Description
To keep up on important incidents on your site without having to dig through server logs the alternative can be custom logs.
Initial Title
Custom Logging Site Events
Initial Tags
security
Initial Language
PHP