<commit_before><?php
namespace Barryvanveen\Logs;

use App;
use Barryvanveen\Mailers\ExceptionMailer;
use Config;
use Log;
use Redirect;
use Response;
use View;

class Logger
{
    /**
     * Handle an exeption (log, email) and redirect to view.
     *
     * @param $exception
     * @param $template
     * @param $responseCode
     *
     * @return Response
     */
    public static function logAndRedirectToView($exception, $template, $responseCode)
    {
        Log::error($exception);

        self::mailException($exception);

        self::returnIfDebuggingEnabled();

        return Response::make(View::make($template), $responseCode);
    }

    /**
     * Handle an exeption (log, email) and redirect back with errors.
     *
     * @param $exception
     * @param $input
     * @param $errors
     *
     * @return Redirect
     */
    public static function logAndRedirectBackWithErrors($exception, $input = null, $errors)
    {
        Log::info($exception);

        self::mailException($exception);

        self::returnIfDebuggingEnabled();

        return Redirect::back()->withInput($input)->withErrors($errors);
    }

    /**
     * Mail an exception to keep the webmaster informed.
     *
     * @param $exception
     */
    public static function mailException($exception)
    {
        if (!App::environment('local')) {
            /** @var ExceptionMailer $mailer */
            $mailer = App::make('Barryvanveen\Mailers\ExceptionMailer');
            $mailer->sendExceptionMail($exception);
        }
    }

    /**
     * Return nothing in case debugging is enabled.
     * This will display the Whoops error page with full debugging info.
     */
    public static function returnIfDebuggingEnabled()
    {
        if (Config::get('app.debug')) {
            return;
        }
    }
}<commit_msg>add some context (referer, current url, ip) to all logged items<commit_after><?php
namespace Barryvanveen\Logs;

use App;
use Barryvanveen\Mailers\ExceptionMailer;
use Config;
use Log;
use Redirect;
use Response;
use View;

class Logger
{
    /**
     * Handle an exeption (log, email) and redirect to view.
     *
     * @param $exception
     * @param $template
     * @param $responseCode
     *
     * @return Response
     */
    public static function logAndRedirectToView($exception, $template, $responseCode)
    {
        Log::error($exception, self::getContext());

        self::mailException($exception);

        self::returnIfDebuggingEnabled();

        return Response::make(View::make($template), $responseCode);
    }

    /**
     * Handle an exeption (log, email) and redirect back with errors.
     *
     * @param $exception
     * @param $input
     * @param $errors
     *
     * @return Redirect
     */
    public static function logAndRedirectBackWithErrors($exception, $input = null, $errors)
    {
        Log::info($exception, self::getContext());

        self::mailException($exception);

        self::returnIfDebuggingEnabled();

        return Redirect::back()->withInput($input)->withErrors($errors);
    }

    /**
     * Mail an exception to keep the webmaster informed.
     *
     * @param $exception
     */
    public static function mailException($exception)
    {
        if (!App::environment('local')) {
            /** @var ExceptionMailer $mailer */
            $mailer = App::make('Barryvanveen\Mailers\ExceptionMailer');
            $mailer->sendExceptionMail($exception);
        }
    }

    /**
     * Return nothing in case debugging is enabled.
     * This will display the Whoops error page with full debugging info.
     */
    public static function returnIfDebuggingEnabled()
    {
        if (Config::get('app.debug')) {
            return;
        }
    }

    protected static function getContext()
    {
        return [
            'referer' => \URL::previous(),
            'url' => \URL::current(),
            'ip' => \Request::ip(),
        ];
    }
}
{'fraction_non_alphanumeric': 0.1249049911325057, 'fraction_numerical': 0.0, 'mean_word_length': 2.424111014744146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '6243256', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1088, 'n_words': 273}