1

任意のログ ファイルに書き込むことができる単純なクラスがあります。

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class Mylog
{
   public function __construct($log, $level = 'debug')
   {
      $this->monolog = new Logger($log);

      $level = constant('Logger::'.strtoupper($level));

      $this->monolog->pushHandler(new StreamHandler(storage_path('logs/'.$log.'-'.date('Y-m-d').'.txt')), $level);
   }

   public function __call($method, $arguments)
   {
      $this->monolog->{$method}($arguments[0]);
   }
}

これにより、次のエラーが表示されます:constant(): Couldn't find constant Logger::DEBUG

ただし、ハンドラーをプッシュするときに、$level を単純に Logger::DEBUG に置き換えると、機能します。実際には定数が存在するのに、定数が見つからないのはなぜですか?

4

1 に答える 1