Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error log on laravel 5 with the url where error occured

I want to append to each error log, the url of the page the user requested before the error occured. The logs already give me where the error occurs, but it's valuable for me know the url.

I saw there is a Handler.php file but how can I append the url there?

like image 891
sebasparola Avatar asked Feb 10 '16 17:02

sebasparola


People also ask

What is a log file in Laravel?

A log file is a file that keeps a registry or records of events, processes, messages that occur in the operating system or any software runs. -Laravel provides the robust logging services that allow the user to log messages to file. -Laravel uses the Monolog library, which is an existing standard logging library for PHP.

How to set the default location for error log in Laravel?

We can set a different location for error log via directive ‘ErrorLog’. there. After that, we have to set the Log Severity Levels. In laravel, there are different severity or security levels. By default, Laravel writes all the log levels to its storage. By default, Laravel comes with level ‘debug‘, which stores all messages.

What are the different logging modes in Laravel?

Laravel supports different logging modes like single, daily, syslog, and errorlog modes. You can set these modes in config/app.php file. You can see the generated log entries in storage/logs/laravel.log file.

Why should I restart the Laravel server after changing app_debug?

Note − After changing the APP_DEBUG variable, you should restart the Laravel server. Logging is an important mechanism by which system can log errors that are generated. It is useful to improve the reliability of the system.


1 Answers

Even better way of doing this:

In App\Exceptions\Handler extend Laravel's base context() function:

use Throwable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;


/**
 * Get the default context variables for logging.
 *
 * @return array
 */
protected function context()
{
    try {
        return array_filter([
            'url' => Request::fullUrl(),
            'input' => Request::except(['password', 'password_confirmation']),
            'userId' => Auth::id(),
            'email' => Auth::user() ? Auth::user()->email : null,
        ]);
    } catch (Throwable $e) {
        return [];
    }
}
like image 196
fsasvari Avatar answered Oct 04 '22 17:10

fsasvari