I am looking for a way in which all the errors will be logged automatically with one line of code. If you know Asp.NET, you probably know what I mean like using Application_Error event handler.
I checked PHP Logging framework? question in SO but they all look same, you should log each and every log message manually which means I need to call the log function everywhere I want to log.
What I am looking for not something like this (which is used by KLogger)
require_once 'KLogger.php';
...
$log = new KLogger ( "log.txt" , KLogger::DEBUG );
// Do database work that throws an exception
$log->LogError("An exception was thrown in ThisFunction()");
// Print out some information
$log->LogInfo("Internal Query Time: $time_ms milliseconds");
// Print out the value of some variables
$log->LogDebug("User Count: $User_Count");
You can create your own custom error handler function in PHP and set it as the error handler
something like:
and to set this function as your default error handler for PHP add this line:
All errors will now be handled by PHP based on what is written inside
handle_error