I've got a simple class that allows me to write to any log file:
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)
The class name inside a string like in the argument to the
constant() function must be fully qualified. When you do Logger::DEBUG it works because the class is
use'd, so it resolves as
Monolog\Logger::DEBUG but in the string it just remains
Logger::DEBUG and that obviously does not exist.
Therefore the solution is simply to use the fully qualified name within strings, i.e.
$level = constant('Monolog\Logger::'.strtoupper($level));