Skip to content

Instantly share code, notes, and snippets.

@rscata
Created June 27, 2013 09:33
Show Gist options
  • Save rscata/5875202 to your computer and use it in GitHub Desktop.
Save rscata/5875202 to your computer and use it in GitHub Desktop.
error log
<?php
error_log('A connection to the database could not be opened.', 1, '[email protected]'); //send error to email
error_log('A connection to the database could not be opened.', 3, '/var/log/php_errors.log'); //log into a file
?>
<?php
//shows an example of an error handler that writes logs into a file and rotates the logfile when it gets above 1 KB.
function log_roller($error, $errorString)
{
$file = '/var/log/php_errors.log';
if(filesize($file) > 1024) {
rename($file, $file . (string) time());
clearstatcache();
}
}
error_log($errorString, 3, $file);
set_error_handler('log_roller');
for($i = 0; $i < 5000; $i++) {
trigger_error(time() . ": Just an error, ma'am.\n");
}
restore_error_handler();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment