Php Laravel 5移除堆栈跟踪

Php Laravel 5移除堆栈跟踪,php,laravel,laravel-5,stack-trace,Php,Laravel,Laravel 5,Stack Trace,如何从Laravel 5中关闭或删除堆栈跟踪。如果你想在你的控制台上阅读它们,它们会让人讨厌。我知道您可以在app/Exceptions/handler.php中添加自定义处理程序,但我不知道如何做到这一点 在env文件中简单地设置APP_DEBUG=false。在文件中设置APP_DEBUG=false。env文件在前端工作正常 如果不希望仅在日志文件中输出堆栈跟踪行,请尝试此操作 在/app/Exceptions/Handler.php中添加使用日志在顶部,然后将其添加到报告功能中: Log

如何从Laravel 5中关闭或删除堆栈跟踪。如果你想在你的控制台上阅读它们,它们会让人讨厌。我知道您可以在
app/Exceptions/handler.php
中添加自定义处理程序,但我不知道如何做到这一点

在env文件中简单地设置
APP_DEBUG=false

文件中设置
APP_DEBUG=false
。env
文件在前端工作正常

如果不希望仅在日志文件中输出堆栈跟踪行,请尝试此操作

/app/Exceptions/Handler.php中添加
使用日志在顶部,然后将其添加到报告功能中:

Log::error('['.$e->getCode().'] "'.$e->getMessage().'" on line '.$e->getTrace()[0]['line'].' of file '.$e->getTrace()[0]['file']);
并删除:

parent::report($e);

更多信息:

由于我无法评论或编辑@Harold answer,以下是一个改进的解决方案:

  • 在/app/Exceptions/Handler.php中添加使用日志;在高层
  • 然后修改报告功能:
  • 公共职能报告(例外$e) { 如果(!config('app.debug')){ 日志::错误('['.$e->getCode().].'.$e->getMessage().''在文件''.$e->getTrace()[0]['line'].'的第'.$e->getTrace()[0]['file']行上); }否则{ 家长:报告(e美元); } }
    哈罗德和贾尼的回答是正确的

    但是,日志行不如默认行详细

    最好的解决方案是编辑文件:

    vendor/laravel/frameworks/src/illumb/Log/LogManager.php

    并在调用includeStacktraces方法时添加false参数

    加错

    $formatter->includeStacktraces()

    因此:

    $formatter->includeStacktraces(假)

    这将简单地禁用stacktrace。其他一切都是一样的。

    对于那些不喜欢“添加这个,删除那个”这类指令的人,以下是
    app/Exceptions/Handler.php
    应该是什么样子,基于Laravel 5.7,并坚持像php本机一样的消息格式:

    <?php
    
    namespace App\Exceptions;
    
    use Log;
    use Exception;
    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
    use Illuminate\Auth\AuthenticationException;
    
    
    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.
         *
         * @param  \Exception  $exception
         * @return void
         */
        public function report(Exception $exception)
        {
            Log::error(sprintf(
                "Uncaught exception '%s' with message '%s' in %s:%d",
                get_class($exception),
                $exception->getMessage(),
                $exception->getTrace()[0]['file'],
                $exception->getTrace()[0]['line']
            ));
            // parent::report($exception);
        }
    
        /**
         * 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);
        }
    }
    

    这就是我要找的,我不希望堆栈跟踪显示在我的日志文件中。这不起作用“最佳解决方案”从不涉及编辑供应商子目录中的文件。
    
    <?php
    
    namespace App\Exceptions;
    
    use Log;
    use Exception;
    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
    use Illuminate\Auth\AuthenticationException;
    
    
    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.
         *
         * @param  \Exception  $exception
         * @return void
         */
        public function report(Exception $exception)
        {
            Log::error(sprintf(
                "Uncaught exception '%s' with message '%s' in %s:%d",
                get_class($exception),
                $exception->getMessage(),
                $exception->getTrace()[0]['file'],
                $exception->getTrace()[0]['line']
            ));
            // parent::report($exception);
        }
    
        /**
         * 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);
        }
    }