This is for debugging only. Ok, again…. this is for debugging only. If you use this REMOVE it once it goes live. At worst you forget to add the tag that clears the log file each time and it bloats horribly and your site gets progressively slower and slower, then your server will crash, you’ll get fired and end up homeless. But if you remove it when your done it’s pretty handy.
This goes in a helper file of your choosing and make sure you load it:
$this->load->helper('the_helper_where_you_put_this_code');
Then put this in the helper file you loaded
if ( ! function_exists('app_log')) {
function app_log($arg) {
// this is your log file, so I referenced it by viewing
// domain.com/applog.htm
$log = './applog.htm';
// to empty the file and start over the first call should begin with init_log
if( preg_match(“/^init_log/”, $arg) ) {
// writes the the file name and whatever the arg is at the start of the file
if (!write_file($log, ''.$arg, 'w') ) {
// or dies
die( 'Unable to write to log file');
}
} else {
// adds whatever the $arg is to the end of the file
if ( ! write_file($log, ''.$arg, 'a+')) {
// or dies
die( 'Unable to write to log file');
}
}
}
}
To use the helper:
app_log('init_log -> Whatever you want goes here');
I usually make the above call in the constructor, then after that in your methods whatever you want to track use:
app_log('blah blah blah');
Sorry, the comment form is closed at this time.