Zend\Log\Logger vs Monolog\Logger

Monolog is my logger of choise, but as far as I can tell, the Zend\Log component is just as good. I would have loved to have an interchangable situation, but that is not going to happen anytime soon.

This is an example of the Zend\Log:

        $logger = new \Zend\Log\Logger;
        $writer = new \Zend\Log\Writer\Stream('/home/robert/example.log');
        $logger->addWriter($writer);
        $logger->warn($'A warning message');
        $logger->log($logger::WARN, 'Another warning message');

This is an example of the Monolog:

        $logger = new Logger('Monolog_voorbeeld');
        $logger->pushHandler(new StreamHandler('/home/robert/example.log', Logger::WARNING));
        $logger->addWarning('A warning message');
        $logger->log($logger::WARNING, 'Another warning message');

 

The methods for adding a warning are different. There is a common log() method in the last lines that look alike, but the contant naming is different. It looks like you will have to deal with the differences if you want to swap the loggers.

Tags:

Share: