Error log class

Views: 1434 Last modified: August 03rd, 2011 Comments: 0

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!!');
?>
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {2+4} =  
    Anything to add ?

        You must be logged in to post a comment.