2017-04-27 92 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 

改变了以“调试”,现在它的正常工作。

相关问题