C
C
Cat Anton2014-12-04 15:03:12
Zend Framework
Cat Anton, 2014-12-04 15:03:12

How to make Logger catch exceptions in ZF2?

Inside the onBootstrap module I create a logger:

use Zend\Log\Writer\Stream as LogWriterStream;
use Zend\Log\Formatter\Simple as LogFormatter;

$logger = new Logger(array(
    'exceptionhandler' => true,
    'errorhandler' => true,
    'fatal_error_shutdownfunction' => true,
));

$filepath = './data/logs/php/' . date('Y-m-d') . '.log';
$writer = new LogWriterStream($filepath);

$formatter = new LogFormatter(null, 'd.m.Y H:i:s');
$writer->setFormatter($formatter);

$logger->addWriter($writer);

The logger builds without errors and creates the 2014-12-04.log file.
Errors like "Division by zero" or "Call to undefined function", the logger successfully catches and writes to the file.
When an exception is thrown, page 500 is displayed with information about the exception, but the logger does not write anything to the file. Why is this happening and how can I make the logger catch exceptions?
Found this answer on SO
stackoverflow.com/questions/15271250/how-to-log-zf...
In fact, here they write their own implementation of a function that is much better implemented in the Logger itself, and which should be used if 'exceptionhandler' = = true
https://github.com/zendframework/zf2/blob/master/l...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shirshov Alexander, 2014-12-06
@Keanor

Can you give an example of an exception? Some exceptions are not caught at all...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question