在测试环境执行后台任务的时候碰到报错:Fatal error: Uncaught Error: Class Psr\Log\NullLogger not found in /var/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php:540 ,PHP环境7.1.33

    在本地环境执行正常,放到测试服务器上报找不到类。而这些类都是通过vendor加载的。解决办法在composer中添加psr/log配置,更新composer依赖。确保vendor\psr\log目录存在。

#composer.json配置
"php": "^7.0",
"psr/log": "~1.0",
"elasticsearch/elasticsearch": "^6.0"

    NullLogger is a class provided by psr/log which is a hard requirement for this package. If you want to install it without composer, the readme tells you to make sure to install dependencies。不过想一下为什么我这在本地开发能正常,放到测试环境才报这个错误呢?想想有一个可能,我本地的代码提交到仓库时是忽略了log目录的,因为根目录下的log存放的日志不用提交至仓库,而log是一个递归的排除,即psr下的log目录一开始就存在于我本地,只是没有提交仓库。于是我在本地将log目录改名发现也同样报Psr\Log\NullLogger的错误。说明并不是psr/log不存在,而是未提交到测试环境。因为psr/log目录理论上是在使用composer时自动就会加载的。

相关评论(0)
您是不是忘了说点什么?

友情提示:垃圾评论一律封号...

还没有评论,快来抢沙发吧!