2017-04-27 89 views
0

我在從控制檯記錄某些基本信息行時遇到問題。在本地,這項工作正常,所有事情都從Web和控制檯記錄(錯誤,信息消息)。但在服務器上,錯誤記錄工作正常,但是當我自己調用記錄器並嘗試記錄某些信息消息時,它不起作用。Monolog無法在服務器上的Laravel控制檯上工作

我正在使用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'); 

回答

0

想通了,我添加了多個消息類型:

$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 

改變了以「調試」,現在它的正常工作。

相關問題