Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monolog: how to catch all errors and exceptions

Tags:

php

monolog

I'm missing something really obvious.

How can I make monolog record all php errors, php user errors, and exceptions?

Before using monolog, I wrote my own functions which I passed to set_error_handler(), register_shutdown_function() and set_exception_handler(). Is there a way of doing this using Monolog's API, or do I have to the following?

  1. Write an error handler and exception handler which I pass to PHP's functions above
  2. In those handlers, call the appropriate Monolog functions such as Logger::addError(...) using a switch statement or similar

Surely there must be a Monolog API that does the above in a single call?

like image 564
CL22 Avatar asked Oct 30 '22 18:10

CL22


1 Answers

From the ErrorHandler class docs:

use Monolog\ErrorHandler;
$logger = new Logger('Logger Name');

ErrorHandler::register($logger);
like image 76
Aidan Ewen Avatar answered Nov 02 '22 11:11

Aidan Ewen