[英]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.