This class will allow you to log errors accordingly. By default you can log MySQL errors, PHP_errors and common errors, which is obvisouly a option to your own needs.
<?php
/**
* Error class
* Store PHP and/or MySQL errors
*/
class Error_Log
{
const MySQLError = '../logs/multi.txt';
const PHP_Error = '/home/vhosts/domain/httpdocs/test/php.txt';
const Common_Error = '/home/vhosts/domain/httpdocs/test/Common.txt';
public function MySQLError($User, $Error)
{
$Date = date('Y-m-d - H:i:s');
$Error = "User: ".$User." @ ".$Date."\nError: ".$Error."\n\r";
error_log($Error, 3, self::MySQLError);
}
public function PHP_Error($User, $Error)
{
$Date = date('Y-m-d - H:i:s');
$Error = "User: ".$User." @ ".$Date."\nError: ".$Error['message']." @ Line: ".$Error['line']." @ file: ".$Error['file']."\n\r";
error_log($Error, 3, self::PHP_Error);
}
public function Common_Error($User, $Error)
{
$Date = date('Y-m-d - H:i:s');
$Error = "User: ".$User." @ ".$Date."\nError: ".$Error."\n\r";
error_log($Error, 3, self::Common_Error);
}
}
// Create warning: Undefined variable
echo $undefinedvar;
// Create instance
$Log = new Error_Log;
// Log php error
$Log->PHP_Error('Laurens', error_get_last());
// MySQL error
$Log->MySQLError('Laurens', 'MySQL error!!');
// Common error
$Log->Common_Error('Laurens', 'Common error!!');
?>
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments