can anybody help on this :

(Psr\Log\InvalidArgumentException): Level "" is not defined, use one of: 100, 200, 250, 300, 400, 500, 550, 600
vendor\monolog\monolog\src\Monolog\Logger.php(256): Monolog\Logger::getLevelName(NULL) lib\internal\Magento\Framework\Logger\Monolog.php(24): Monolog\Logger->addRecord(NULL, 'Tagalys Request...', Array)

This is how i have used logger

protected $logger;
public function __construct(
\Psr\Log\LoggerInterface $logger,
 ) {
     $this->logger = $logger;   

public function xyz(){
$this->logger->log(null, 'Tagalys Request Object: '.json_encode($payload)); 

I am not getting any log files

1 Answer 1


When you use the \Psr\Log\LoggerInterface the first parameter must be a level of log.

Different levels can be found under Psr\Log\LogLevel :

class LogLevel
    const EMERGENCY = 'emergency';
    const ALERT = 'alert';
    const CRITICAL = 'critical';
    const ERROR = 'error';
    const WARNING = 'warning';
    const NOTICE = 'notice';
    const INFO = 'info';
    const DEBUG = 'debug';

So if you want to log for example a debug information you'll have to call:

$this->logger->log(\Psr\Log\LogLevel::DEBUG, 'Tagalys Request Object: '.json_encode($payload));

To avoid having to specify the level of log, the class provides one method per level so instead of the code above, you can also do:

$this->logger->debug('Tagalys Request Object: '.json_encode($payload));

The other methods available are:

  • emergency()
  • alert()
  • critical()
  • error()
  • warning()
  • notice()
  • info()

Using this class you cannot specify a custom log file.

If you want to do so you can use the following code:

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/mylogfile.log');
$logger = new \Zend\Log\Logger();
$logger->info('Your text message');
  • Thanks, Raphael, but can i give a custom log file instead of debug.log as follows: $this->logger->debug('Tagalys Request Object: '.json_encode($payload), null, 'mylogfile.log');
    – Sushivam
    Commented Jun 20, 2016 at 13:24
  • I get Argument 3 passed to Monolog\Logger::log() must be of the type array, null given
    – Sushivam
    Commented Jun 20, 2016 at 13:25
  • i tried this too: $this->logger->log(\Psr\Log\LogLevel::DEBUG, 'Tagalys Request Object: '.json_encode($payload),'tagalys.log'); i get same error
    – Sushivam
    Commented Jun 20, 2016 at 13:27
  • @SachinS see my updated answer ;) Commented Jun 20, 2016 at 13:29
  • How to pass json_encode($payload) into the $writer
    – Sushivam
    Commented Jun 20, 2016 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.