Laravel问题:Undefined variable : logger

起因

因为laravel项目默认的日志格式为single,显然这对于查看而言是非常不舒服了。不过laravel日志了也同样提供了另外几种模式。

  • single —— 将日志记录到单个文件中。该日志处理器对应Monolog的StreamHandler
  • daily —— 以日期为单位将日志进行归档,每天创建一个新的日志文件记录日志。该日志处理器 对应Monolog的RotatingFileHandler
  • syslog —— 将日志记录到syslog中。该日志处理器 对应Monolog的SyslogHandler
  • errorlog —— 将日志记录到PHP的error_log中。该日志处理器 对应Monolog的ErrorLogHandler

于是笔者就更改日志格式,但神奇的事情出现了。当代码错误时,竟然直接抛出500的Nginx错误,而无法渲染Exception错误页面。这就让尴尬了。于是开始寻找是不是哪里出错了。

查询服务器日志

因为直接服务器报错,那么就去查询服务器错误日志;但查询无果,nginx竟然没有错误日志。
于是开始翻查php错误日志,果不其然,还真报错了。内容如下:

php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught ErrorException: Undefined variable: logger in /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:69"
nginx_1               | Stack trace:
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "Stack trace:"
nginx_1               | #0 /var/www/student/vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#0 /var/www/student/vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)"
nginx_1               | #1 /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(69): Raven_Breadcrumbs_ErrorHandler->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#1 /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(69): Raven_Breadcrumbs_ErrorHandler->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#2 /var/www/student/app/Exceptions/Handler.php(61): Illuminate\Foundation\Exceptions\Handler->report(Object(InvalidArgumentException))"
nginx_1               | #2 /var/www/student/app/Exceptions/Handler.php(61): Illuminate\Foundation\Exceptions\Handler->report(Object(InvalidArgumentException))
php-fpm_1             | 172.21.0.6 -  11/May/2017:23:06:19 +0000 "GET /index.php" 500
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#3 /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(80): App\Exceptions\Handler->report(Object(ErrorException))"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#4 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(ErrorException))"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#5..."
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught ErrorException: Undefined variable: logger in /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:69"
nginx_1               | #3 /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(80): App\Exceptions\Handler->report(Object(Symfony\Component\Debug\Exception\FatalErrorException))
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "Stack trace:"
nginx_1               | #4 /var/www/student/vendor
nginx_1               | 172.21.0.1 - - [11/May/2017:23:04:55 +0000] "GET /class/43f5a10c66e34f258633cb8a1332fe16/teacher HTTP/1.1" 200 2724 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#0 /var/www/student/vendor/sentry/sentry/lib/Raven/Breadcrumbs/ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#1 /var/www/student/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(69): Raven_Breadcrumbs_ErrorHandler->handleError(8, 'Undefined varia...', '/var/www/studen...', 69, Array)"
nginx_1               | 172.21.0.1 - - [11/May/2017:23:04:55 +0000] "GET /favicon.ico HTTP/1.1" 200 0 "http://student.itxdl.cn/class/43f5a10c66e34f258633cb8a1332fe16/teacher" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
php-fpm_1             | [11-May-2017 23:06:21] WARNING: [pool www] child 7 said into stderr: "#2 /var/www/student/app/Exceptions/Handler.php(61): Illuminate\Foundation\Exceptions\Handler->report(Object(InvalidArgumentException))"
nginx_1               | 172.21.0.1 - - [11/May/2017:23:05:10 +0000] "GET /class/43f5a10c66e34f258633cb8a1332fe16/teacher HTTP/1.1" 500 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"

定位错误

  1. 发现不存在logger变量,这一定时改了哪个地方。于是开始回退代码版本,这时发现依然无法解决。
  2. 新建项目,看是否为环境问题。发现新项目没有问题,这时环境没问题。
  3. 于是发现.env文件配错啦。

错误代码

# .env
...
APP_DEBUG=true
APP_LOG_LEVEL=daily
APP_URL=
...
# app.php
'log' => env('APP_LOG', 'single'),
'log_level' => env('APP_LOG_LEVEL', 'debug'),

LOG_LEVEL误以为Log日志文件模式,其实为报错级别。

解决

#.env
APP_LOG_LEVEL=debug
APP_LOG=daily

你可能感兴趣的:(Laravel问题:Undefined variable : logger)