Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save summercms/e9eea014c184a160d9ee53acee18a343 to your computer and use it in GitHub Desktop.

Select an option

Save summercms/e9eea014c184a160d9ee53acee18a343 to your computer and use it in GitHub Desktop.
Removing the error stack traces from logging in Laravel

Removing the error stack traces from logging in Laravel

By default errors in Laravel are logged with the error stack traces. If you want to turn off these annoying stack traces perform the following:

  1. Open
app/Exceptions/Handler.php`
  1. Add
 use Illuminate\Support\Facades\Log;`
  1. Modify the report method:
/**
  * Report or log an exception.
  *
  * @param  \Exception  $exception
  * @return void
  */
  public function report(Exception $exception)
  {

      // Some exceptions don't have a message
      $exception_message = (!empty($exception->getMessage()) ? trim($exception->getMessage()) : 'App Error Exception');

      // Log message
      $log_message = "\"" . $exception_message . " in file '" . $exception->getFile() . "' on line '" . $exception->getLine() . "'" . "\"";

      if (!config('app.debug')) {
          Log::error($log_message);
      } else {
          parent::report($exception);
      }
  }

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment