<commit_before><?php
/**
 * Logger class - Custom errors
 *
 * @author <NAME> - <EMAIL>
 * @version 2.2
 * @date June 27, 2014
 * @date updated Sept 19, 2015
 */

namespace Smvc\Core;

use Smvc\Helpers\PhpMailer\Mail;

/**
 * Record and email/display errors or a custom error message.
 */
class Logger
{
    /**
    * Determins if error should be emailed to SITEEMAIL defined in app/Core/Config.php.
    *
    * @var boolean
    */
    private static $emailError = false;

    /**
    * Clear the errorlog.
    *
    * @var boolean
    */
    private static $clear = false;

    /**
    * show the error.
    *
    * @var boolean
    */
    private static $display = false;

    /**
    * Path to error file.
    *
    * @var string
    */
    public static $errorFile = ROOT.'tmp/logs/error.log';

    /**
    * store errors for output.
    *
    * @var string
    */
    public static $error;

    /**
    * In the event of an error show this message.
    */
    public static function customErrorMsg()
    {
        if (self::$display) {
            echo '<pre>'.self::$error.'</pre>';
        } else {
            echo "<p>An error occured, The error has been reported.</p>";
            exit;
        }

    }

    /**
    * Saved the exception and calls customer error function.
    *
    * @param  exeption $e
    */
    public static function exceptionHandler($e)
    {
        self::newMessage($e);
    }

    /**
    * Saves error message from exception.
    *
    * @param  numeric $number  error number
    * @param  string  $message the error
    * @param  string  $file    file originated from
    * @param  numeric $line    line number
    */
    public static function errorHandler($number, $message, $file, $line)
    {
        $msg = "$message in $file on line $line";

        if (($number !== E_NOTICE) && ($number < 2048)) {
            self::errorMessage($msg);
            self::$error = $msg;
            self::customErrorMsg();
        }

        return 0;
    }

    /**
    * New exception.
    *
    * @param  Exception $exception
    * @param  boolean   $printError show error or not
    * @param  boolean   $clear       clear the errorlog
    * @param  string    $errorFile  file to save to
    */
    public static function newMessage($exception)
    {
        $message = $exception->getMessage();
        $code = $exception->getCode();
        $file = $exception->getFile();
        $line = $exception->getLine();
        $trace = $exception->getTraceAsString();
        $trace = str_replace(DB_PASS, '********', $trace);
        $date = date('M d, Y G:iA');
        $systempath = dirname(__DIR__);

        $logMessage = "Exception information:\n
           Date: {$date}\n
           Message: {$message}\n
           Code: {$code}\n
           File: {$file}\n
           Line: {$line}\n
           Stack trace:\n
           {$trace}\n
           ---------\n\n";

        if (is_file($systempath.self::$errorFile) === false) {
            file_put_contents($systempath.self::$errorFile, '');
        }

        if (self::$clear) {
            $f = fopen($systempath.self::$errorFile, "r+");
            if ($f !== false) {
                ftruncate($f, 0);
                fclose($f);
            }
        }

        // Append
        file_put_contents($systempath.self::$errorFile, $logMessage, FILE_APPEND);

        self::$error = $logMessage;
        self::customErrorMsg();

        //send email
        self::sendEmail($logMessage);
    }

    /**
    * Custom error.
    *
    * @param  string  $error       the error
    * @param  boolean $printError display error
    * @param  string  $errorFile  file to save to
    */
    public static function errorMessage($error)
    {
        $date = date('Y-m-d G:iA');
        $logMessage = "$date - $error\n\n";
        $systempath = dirname(__DIR__);

        if (is_file($systempath.self::$errorFile) === false) {
            file_put_contents($systempath.self::$errorFile, '');
        }

        if (self::$clear) {
            $f = fopen($systempath.self::$errorFile, "r+");
            if ($f !== false) {
                ftruncate($f, 0);
                fclose($f);
            }

            $content = null;
        } else {
            // Append
            file_put_contents($systempath.self::$errorFile, $logMessage, FILE_APPEND);<commit_msg>Fix the error file setup.<commit_after><?php
/**
 * Logger class - Custom errors
 *
 * @author <NAME> - <EMAIL>
 * @version 2.2
 * @date June 27, 2014
 * @date updated Sept 19, 2015
 */

namespace Smvc\Core;

use Smvc\Helpers\PhpMailer\Mail;

/**
 * Record and email/display errors or a custom error message.
 */
class Logger
{
    /**
    * Determins if error should be emailed to SITEEMAIL defined in app/Core/Config.php.
    *
    * @var boolean
    */
    private static $emailError = false;

    /**
    * Clear the errorlog.
    *
    * @var boolean
    */
    private static $clear = false;

    /**
    * show the error.
    *
    * @var boolean
    */
    private static $display = false;

    /**
    * Path to error file.
    *
    * @var string
    */
    public static $errorFile = null;

    /**
    * store errors for output.
    *
    * @var string
    */
    public static $error;

    /**
    * In the event of an error show this message.
    */
    public static function customErrorMsg()
    {
        if (self::$display) {
            echo '<pre>'.self::$error.'</pre>';
        } else {
            echo "<p>An error occured, The error has been reported.</p>";
            exit;
        }

    }

    /**
    * Saved the exception and calls customer error function.
    *
    * @param  exeption $e
    */
    public static function exceptionHandler($e)
    {
        self::newMessage($e);
    }

    /**
    * Saves error message from exception.
    *
    * @param  numeric $number  error number
    * @param  string  $message the error
    * @param  string  $file    file originated from
    * @param  numeric $line    line number
    */
    public static function errorHandler($number, $message, $file, $line)
    {
        $msg = "$message in $file on line $line";

        if (($number !== E_NOTICE) && ($number < 2048)) {
            self::errorMessage($msg);
            self::$error = $msg;
            self::customErrorMsg();
        }

        return 0;
    }

    /**
    * New exception.
    *
    * @param  Exception $exception
    * @param  boolean   $printError show error or not
    * @param  boolean   $clear       clear the errorlog
    * @param  string    $errorFile  file to save to
    */
    public static function newMessage($exception)
    {
        self::$errorFile = ROOT.'tmp/logs/error.log';

        $message = $exception->getMessage();
        $code = $exception->getCode();
        $file = $exception->getFile();
        $line = $exception->getLine();
        $trace = $exception->getTraceAsString();
        $trace = str_replace(DB_PASS, '********', $trace);
        $date = date('M d, Y G:iA');
        $systempath = dirname(__DIR__);

        $logMessage = "Exception information:\n
           Date: {$date}\n
           Message: {$message}\n
           Code: {$code}\n
           File: {$file}\n
           Line: {$line}\n
           Stack trace:\n
           {$trace}\n
           ---------\n\n";

        if (is_file($systempath.self::$errorFile) === false) {
            file_put_contents($systempath.self::$errorFile, '');
        }

        if (self::$clear) {
            $f = fopen($systempath.self::$errorFile, "r+");
            if ($f !== false) {
                ftruncate($f, 0);
                fclose($f);
            }
        }

        // Append
        file_put_contents($systempath.self::$errorFile, $logMessage, FILE_APPEND);

        self::$error = $logMessage;
        self::customErrorMsg();

        //send email
        self::sendEmail($logMessage);
    }

    /**
    * Custom error.
    *
    * @param  string  $error       the error
    * @param  boolean $printError display error
    * @param  string  $errorFile  file to save to
    */
    public static function errorMessage($error)
    {
        self::$errorFile = ROOT.'tmp/logs/error.log';

        $date = date('Y-m-d G:iA');
        $logMessage = "$date - $error\n\n";
        $systempath = dirname(__DIR__);

        if (is_file($systempath.self::$errorFile) === false) {
            file_put_contents($systempath.self::$errorFile, '');
        }

        if (self::$clear) {
            $f = fopen($systempath.self::$errorFile, "r+");
            if ($f !== false) {
                ftruncate($f, 0);
                fclose($f);
            }

            $content = null;
        } else {
            // Append
            file_put_contents($systempath.self::$errorFile, $logMessage, FILE_APPEND);
{'fraction_non_alphanumeric': 0.14425594899237162, 'fraction_numerical': 0.00478196515996812, 'mean_word_length': 1.7815072830905636, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1966112', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2627, 'n_words': 661}