[英]Monolog does not work in Laravel Console on server
我在从控制台记录一些基本信息行时遇到问题。 在本地,这可以正常工作,所有内容都可以通过Web和控制台进行记录(错误,信息消息)。 但是在服务器上,错误日志记录可以正常工作,但是当我自己致电logger并尝试记录一些信息消息时,它将无法正常工作。
我正在使用Laravel 5.4版本。
这是一些App \\ Console \\ Commands \\ DummyCommand类,用于测试。
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Log\Writer as Log;
class DummyCommand extends Command
{
/**
* Create a new console command instance.
*
* @param \Illuminate\Log\Writer $log
* @return void
*/
public function __construct(Log $log)
{
parent::__construct();
$this->log = $log;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$message = "Some dummy message";
$this->info($message); // gets printed on console both locally and on server
$this->log->info($message);
$ret = $this->log->getMonolog()->addInfo($message);
dump($ret); // locally = true, server = false
if ($ret === false) {
throw new \Exception('Error while logging!'); // this log works fine both locally and on server
}
}
}
我在服务器上运行以下命令:
php artisan dummy // prints "Some dummy message" and loggs error message "Error while logging!"
php artisan schedule:run // same thing as above
知道为什么这不起作用吗? 存储文件夹的权限适用于所有文件夹和文件。 错误消息(异常)将被记录,而信息消息则不会。
编辑:这是可行的,我需要在调用$ this-> log-> info();之前添加以下行: 但是我无法在所有命令上使用,并且每次都需要设置日志文件的路径。 (来源: https : //laracasts.com/discuss/channels/general-discussion/logging-in-l5/replies/11771 )
$this->log->useDailyFiles(storage_path().'/logs/laravel.log');
想通了,我添加了多种消息类型:
$this->log->getMonolog()->addAlert($message);
$this->log->getMonolog()->addCritical($message);
$this->log->getMonolog()->addDebug($message);
$this->log->getMonolog()->addError($message);
$this->log->getMonolog()->addWarning($message);
并记录所有带有错误前缀的消息(除信息外的所有消息)。 所以我查看了.env文件,下面是有关日志级别的一行:
APP_LOG_LEVEL=notice
将其更改为“调试”,现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.