Skip to content

Instantly share code, notes, and snippets.

@neuthral
Created June 1, 2019 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuthral/2a4b64a38b6e55f2e7393aa3f84d08be to your computer and use it in GitHub Desktop.
Save neuthral/2a4b64a38b6e55f2e7393aa3f84d08be to your computer and use it in GitHub Desktop.
Laravel log stack one line
<?php
namespace App\Exceptions;
use Log;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
* edited to display only first line of log stack for easy reading...
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $e)
{
// parent::report($e);
$string = '';
if($e->getCode())
$string .= '['.$e->getCode().'] ';
if($e->getMessage())
$string .= $e->getMessage();
if($e->getTrace()[0]['line'])
$string .= ' on line '.$e->getTrace()[0]['line'];
if($e->getTrace()[0]['file'])
$string .= ' of file '.$e->getTrace()[0]['file'];
Log::error($string);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment